EditText에서 텍스트를 설정하는 방법
EditText의 텍스트를 어떻게 설정합니까?
당신이 문서를 확인하면 EditText
, 당신은 찾을 setText()
방법을. a String
와 a를 TextView.BufferType
받습니다. 예를 들면 다음과 같습니다.
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText("Google is your friend.", TextView.BufferType.EDITABLE);
또한 TextView
의 setText(CharSequence)
및 setText(int)
메소드를 상속 하므로 일반처럼 설정 할 수 있습니다 TextView
.
editText.setText("Hello world!");
editText.setText(R.string.hello_world);
String string="this is a text";
editText.setText(string)
String이 CharSequence의 유용한 간접 서브 클래스라는 것을 알았습니다.
http://developer.android.com/reference/android/widget/TextView.html setText (CharSequence text) 찾기
http://developer.android.com/reference/java/lang/CharSequence.html
String text = "Example";
EditText edtText = (EditText) findViewById(R.id.edtText);
edtText.setText(text);
EditText
필요한 경우 문자열 값만 승인 하십시오 . 문자열로 변환하십시오.
int, double, long 값이면 다음을 수행하십시오.
String.value(value);
문자열 연결 연산자 +를 사용하십시오.
ed = (EditText) findViewById (R.id.box);
int x = 10;
ed.setText(""+x);
또는 사용
String.valueOf(int):
ed.setText(String.valueOf(x));
또는 사용
Integer.toString(int):
ed.setText(Integer.toString(x));
당신은 설정할 수 있습니다 android:text="your text"
;
<EditText
android:id="@+id/editTextName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/intro_name"/>
editTextObject.setText(CharSequence)
http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence )
다음을 수행해야합니다.
- 선언
EditText in the xml file
EditText
활동에서 찾기- 텍스트를
EditText
이것이 Kotlin의 솔루션입니다
val editText: EditText = findViewById(R.id.main_et_name)
editText.setText("This is a text.")
Android Java의 솔루션 :
EditText를 시작하십시오 .ID는 xml id에 있습니다.
EditText myText = (EditText)findViewById(R.id.my_text_id);
OnCreate 메소드에서 정의 된 이름으로 텍스트를 설정하십시오.
String text = "here put the text that you want"
editText에서 setText 메소드를 사용하십시오.
myText.setText(text); //variable from point 2
참고 URL : https://stackoverflow.com/questions/4590957/how-to-set-text-in-an-edittext
'development' 카테고리의 다른 글
three.js 배경을 투명 또는 다른 색으로 변경 (0) | 2020.08.03 |
---|---|
10 미만의 int 값은 문자열 두 자리 숫자로 변환 (0) | 2020.08.03 |
iOS 7-상태 표시 줄이보기와 겹칩니다 (0) | 2020.08.03 |
Retrofit 2는 기본 URL에서 호스트 이름 뒤의 문자를 제거합니다 (0) | 2020.08.03 |
외래 키에 인덱스를 만들어야합니까? (0) | 2020.08.02 |