Android: Can an EditText Within a ListView be Focused as Well as the List Item?
I know that when you allow focus to any "focusable" object within a ListView it disables the ability to focus on the ListView itself. I have an EditText and a couple buttons inside my ListView item, but I also want to be able to use a ContextMenu with the ListView so I need to be able to maintain focus. Is there a way to override so that both my ListView and EditText box can receive focus? I assume if it is possible it would be done within the custom adapter. I am using a SimpleCursor开发者_如何学编程Adapter and managing my button clicks within the NewView method. My code is below:
public class GrainListAdapter extends SimpleCursorAdapter {
private Button upButton;
public GrainListAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
int nameColumn = cursor.getColumnIndex("name");
String getName = cursor.getString(nameColumn);
TextView name = (TextView)view.findViewById(R.id.GrainName);
name.setText(getName);
int originColumn = cursor.getColumnIndex("origin");
String getOrigin = cursor.getString(originColumn);
TextView origin = (TextView)view.findViewById(R.id.GrainOrigin);
origin.setText(getOrigin);
int lbsColumn = cursor.getColumnIndex("lbs");
String getLbs = cursor.getString(lbsColumn);
EditText lbs = (EditText)view.findViewById(R.id.GrainLbs);
lbs.setText(getLbs);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = View.inflate(context, R.layout.grain_list_item, null);
upButton = (Button)view.findViewById(R.id.UpLbsButton);
upButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i("Grain Adapter Action", "Button CLICKED!!!");
}
});
return view;
}
I don't think you can do this. http://www.youtube.com/watch?v=wDBM6wVEO70 The video is long but great info on listview. At one point they explain it would confuse the application to know on which item you were selecting. I would consider adding another button or setting up a longclicklistener() and sharing it across all items in the listview.
精彩评论