Reputation: 21
I am developing a custom soft keyboard for Android. I have added a list on the top of the normal keyboard. The list is just a normal ListView. What I need to do is to detect and respond to the click event inside the main program, which is SoftKeyboard.java. The ListView is initialised inside onCreateCandidatesView() method. Here's my code.
suggestion_list.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/candidate_background"
android:divider="#BBCFCFCF"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false" />
SoftKeyboard.java
public class SoftKeyboard extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
//dummy data for the list
private static final String[] items = {"1","2","3"};
//some other variables
@Override
public View onCreateCandidatesView() {
LayoutInflater mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView ls = (ListView)mInflater.inflate(R.layout.suggestion_list,null);
ls.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,items));
ls.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("index", "Clicked");
}
});
return ls;
}
//some other methods
}
But The ListView doesn't seem to respond to the setOnItemClickListener() at all. Could anyone kindly help me on this issue? Thanks a lot!
Update:
I found that even if I use a normal ListView, it still doesn't work. I updated my code above for using a normal ListView.
Upvotes: 2
Views: 715
Reputation: 54322
Try adding
android:descendantFocussability=blocksDescendants
to the top most linear layout.It might work.
Upvotes: 1