在我的活动中,我创建了七个列表视图,并在同一个活动中使用 viewpager 在它们之间滑动。然后我有一个 sqlite 数据库填充每个列表视图。我的问题是 onitemclicklistener 不起作用,没有错误,代码执行良好,但列表项点击没有任何反应。我通过添加 toast 显示消息等对其进行了测试,但列表项点击没有任何反应。
我怀疑问题是我没有像传统方法那样从 xml 布局中获取列表视图,因此 itemclicklistener 方法略有不同,但是我不知道以这种方式使用列表视图时使用什么方法,并且没有其他操作系统线程我已经seen 以这种方式创建列表视图。如果有人可以请阐明一些我会非常感激。提前致谢。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_schedule);
ListView listview1 = new ListView(mContext);
ListView listview2 = new ListView(mContext);
ListView listview3 = new ListView(mContext);
ListView listview4 = new ListView(mContext);
ListView listview5 = new ListView(mContext);
ListView listview6 = new ListView(mContext);
ListView listview7 = new ListView(mContext);
Vector<View> pages = new Vector<View>();
pages.add(listview1);
pages.add(listview2);
pages.add(listview3);
pages.add(listview4);
pages.add(listview5);
pages.add(listview6);
pages.add(listview7);
ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
PageAdapter adapter = new PageAdapter(mContext,pages);
vp.setAdapter(adapter);
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getMonday(),CursorAdapter.NO_SELECTION );
listview1.setAdapter(scheduleAdapter);
db.close();
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getTuesday(),CursorAdapter.NO_SELECTION );
listview2.setAdapter(scheduleAdapter);
db.close();
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getWednesday(),CursorAdapter.NO_SELECTION );
listview3.setAdapter(scheduleAdapter);
db.close();
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getThursday(),CursorAdapter.NO_SELECTION );
listview4.setAdapter(scheduleAdapter);
db.close();
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getFriday(),CursorAdapter.NO_SELECTION );
listview5.setAdapter(scheduleAdapter);
db.close();
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getSaturday(),CursorAdapter.NO_SELECTION );
listview6.setAdapter(scheduleAdapter);
db.close();
db.open();
scheduleAdapter = new ScheduleAdapter(ScheduleActivity.this, db.getSunday(),CursorAdapter.NO_SELECTION );
listview7.setAdapter(scheduleAdapter);
db.close();
listview1.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});