EditText не показывает текст

#java #android #android-layout #listview #android-edittext

#java #Android #android-макет #listview #android-edittext

Вопрос:

Приложение-словарь с listview , Button и EditText . EditText показывает клавиатуру на реальном устройстве при первом нажатии, но на ней не отображаются слова, а затем она больше не появляется. Я много раз пытался найти решение в stack overflow, но ни одно из них не сработало для меня. Кто-нибудь может помочь?

Заранее спасибо.

 public class MainActivity extends AppCompatActivity {
private ListView listView;
List<WordTranslation> quotes;
Button searchBtn;
EditText editText;
DatabaseAccess databaseAccess;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);

}


@Override
protected void onStart() {
    super.onStart();
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
    AlertDialog alert = alertDialog.show();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    return super.onOptionsItemSelected(item);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    searchBtn = (Button) findViewById(R.id.button);
    editText = (EditText) findViewById(R.id.EditText);
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    searchBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        String word=    editText.getText().toString();
            databaseAccess.getwordtranslation(word);
        }
    });


    this.listView = (ListView) findViewById(R.id.ListView);
    final DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this);
    databaseAccess.open();
    databaseAccess.getQuotes();
    quotes = databaseAccess.ShowDictionaryDetails();
    databaseAccess.close();

    ArrayAdapter<String> adapter = new Adapter(this, R.layout.activity_list_view_item, quotes);
    listView.setAdapter(adapter);
    }
  

xml-файл

 <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.future.DictionaryEdition.MainActivity"
android:focusableInTouchMode="true">



<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@ id/line2"
    android:layout_below="@ id/line1">


    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@ id/ListView">


    </ListView>

</LinearLayout>


<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="True"
    android:focusableInTouchMode="true"
    android:id="@ id/line1">
    <!--android:layout_alignRight="@ id/line3">-->


    <!--<SearchView-->
    <!--android:layout_width="match_parent"-->
    <!--android:layout_height="match_parent"-->
    <!--android:layout_weight="1"-->
    <!--android:id="@ id/search_view"/>-->


    <EditText
        android:hint="@string/search_word_here"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@ id/EditText"
        android:focusable="True"
        android:focusableInTouchMode="true"
        android:layout_weight="3"
        android:textColor="@color/colorAccent"
        android:inputType="text" />


    <Button
        android:text="@string/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@ id/button"
        android:layout_weight="1" />
</LinearLayout> </RelativeLayout>
  

Комментарии:

1. убедитесь, что цвет текста не совпадает с цветом фона.

2. да, это другое

Ответ №1:

Потому что, как вы можете видеть в xml-файле, вы ничего не пишете в android:text поле. таким образом, это ничего не даст вам написанного. Так что измените это.

 <EditText
        android:text="balabalbla"
        android:hint="@string/search_word_here"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@ id/EditText"
        android:focusable="True"
        android:focusableInTouchMode="true"
        android:layout_weight="3"
        android:inputType="text" />
  

и напишите что-нибудь на android:text="baablaabla"

Комментарии:

1. Я загрузил файл без редактирования, я удаляю его в данный момент,

2. без разницы.

3. попробуйте clean и rebuild проект.