I want to use listview with SimpleCursorAdapter Class. My problem is I can not click list view.
My Adapter class is....
public class ColorAdapter extends SimpleCursorAdapter {
private Context context;
public ColorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
this.context = context;
}
public int getCount() {
// TODO Auto-generated method stub
return MyArrList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.event_list, null);
}
TextView tname = (TextView) convertView.findViewById(R.id.ename);
tname.setText(MyArrList.get(position).get("EventName"));
TextView tdetail = (TextView) convertView
.findViewById(R.id.edetail);// ใส่ข้อมูลทีละส่วน
tdetail.setText(MyArrList.get(position).get("EventDetail"));
return convertView;
}
}
On click method is....
elist.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent intent = new Intent(getApplicationContext(),
EventsDetail.class);
String eventName = MyArrList.get(position).get("EventName").toString();
intent.putExtra("EventName", eventName);
startActivity(intent);
}
});
When I click listview it nothing happen. Can anybody help me?
I encountered this issue a few days ago, the problem shoube be exist in the list-row-layout, in your list-row layout xml root element, put android:descendantFocusability="blocksDescendants"
, it works for me well.
hope it helpful!