SetText не работает для editText. Я меняю идентификатор edittext, имя и т. д., но он не работает. Может кто-нибудь мне помочь?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
buttonContact = (Button) findViewById(R.id.imageButton1);
buttonSend = (Button) findViewById(R.id.imageButton2);
textPhoneN = (EditText)findViewById(R.id.editText1);
textSMS = (EditText) findViewById(R.id.editTextSMS);
/////////// for set message into compose window
textPhoneN.setText("sdf");
}
TextPhoneN не устанавливает никакого текста в oncreate ().
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#6666E0"
android:gravity="end"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#ffffff"
android:hint="To"
android:inputType="text|phone" >
<requestFocus />
</EditText>
<Button
android:id="@+id/imageButton1"
style="?android:attr/buttonStyleSmall"
android:layout_width="116dp"
android:layout_height="30dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:background="#00004C"
android:text="Add Contact"
android:textColor="#ffffff"
android:textSize="18sp" />
<EditText
android:id="@+id/editTextSMS"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:ems="10"
android:gravity="top"
android:hint="Message"
android:inputType="textMultiLine"
android:lines="5" />
<Button
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00004C"
android:text="Send"
android:textColor="#ffffff" />
</LinearLayout>
Я следую твоему предложению, но все равно безрезультатно
2 ответа
Удалите android:inputType="text|phone"
и попробуйте.
Вы установили android:inputType
для EditText
в своем XML? Например, если вы установите android:inputType="number"
для своего textPhoneN
, вы не сможете установить "sdf"
, потому что это не числовые данные (это не вызовет никаких ошибок, но текст будет не устанавливается)
Вместо этого попробуйте textPhoneN.setText("12345");
Если это тоже не сработает, возможно, ваш EditText
отключен в XML.
Похожие вопросы
Новые вопросы
android
Android — это мобильная операционная система Google, используемая для программирования или разработки цифровых устройств (смартфонов, планшетов, автомобилей, телевизоров, одежды, очков, IoT). Для тем, связанных с Android, используйте теги, специфичные для Android, такие как android-intent, android-activity, android-adapter и т. д. Для вопросов, отличных от разработки или программирования, но связанных с Android framework, используйте эту ссылку: https://android .stackexchange.com.