我想将listview与SimpleCursorAdapter类一起使用。我的问题是我无法点击列表视图 我的适配器类是....
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;
}
}
点击方法是....
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);
}
});
当我点击listview时,没有任何反应。有人能帮助我吗?
答案 0 :(得分:0)
我几天前遇到过这个问题,问题应该存在于list-row-layout中,在你的列表行布局xml根元素中,放置android:descendantFocusability="blocksDescendants"
,它对我很有用。
希望它有用!