<ListView
android:id="@+id/category_choices"
android:choiceMode="singleChoice"
android:layout_width="400dp"
android:layout_height="wrap_content">
</ListView>
<EditText
android:id="@+id/other_please_specify"
android:singleLine="true"
android:layout_height="wrap_content" android:layout_width="326dp"/>
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
android.R.layout.simple_list_item_single_choice, categories);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
selectedItem = (String) (listView.getItemAtPosition(myItemInt));
}
});
I tried the following, but it does not work
editText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (selectedItem != null) {
int checkedItem = listView.getCheckedItemPosition();
listView.setItemChecked(checkedItem, false);
selectedItem = null;
}
return false;
}
});
You have to use Text Watcher for Edit Text to listen for entered text :
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// do your stuffs here
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
Log.e("TextWatcherTest", "afterTextChanged:\t" + s.toString());
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.