【发布时间】:2014-02-28 08:20:33
【问题描述】:
我想将 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 时,什么也没有发生。有人可以帮帮我吗?
【问题讨论】:
标签: android listview click simpleadapter