字典應用程序與listview
,Button
和EditText
。 EditText顯示鍵盤在實際設備上的第一次點擊,但它不顯示的話,並且 然後它不會再出現。 我曾多次嘗試在堆棧溢出中找到解決方案,但都沒有爲我工作。 任何人都可以提供幫助嗎?EditText不顯示文字
在此先感謝。
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>
東西確保文本顏色不匹配的背景。 – Zoe
是的,這是不同的 –