如何处理 1 个 ListActivity 中 2 个列表视图的点击
我是一名 Android 初学者程序员,我想这可能不是最佳实践,但我有一个新闻和类别列表。每个活动都有不同的参数,这些参数会转到另一个活动。我想知道是否有人能如此友善并为此提供解决方法。
nuList = (ListView)findViewById(R.id.list2);
adapter1 = new CategsAdapter(UhoraYCategs.this, names);
nuList.setAdapter(adapter1);
Utility.setListViewHeightBasedOnChildren(nuList);
list = (ListView)findViewById(android.R.id.list);
adapter = new LazyAdapter(UhoraYCategs.this, imgs, titles, catg);
list.setAdapter(adapter);
Utility.setListViewHeightBasedOnChildren(list);
以及每个列表的听众
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(this, UhoraList.class);
i.putExtra("categoria", names[position]);
i.putExtra("xml", urls[position]);
startActivity(i);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(this, NewsIntentPave.class);
i.putExtra("tit", (messages.get(position).getTitle()).toString());
i.putExtra("descric",(messages.get(position).getDescription()).toString());
i.putExtra("fecha", (messages.get(position).getDate()).toString());
i.putExtra("foto", (messages.get(position).getFoto()).toString());
i.putExtra("url", (messages.get(position).getLink()).toString());
i.putExtra("banner", "uhora");
startActivity(i);
}
我怎样才能将每个听众与每个列表相关联?任何帮助将不胜感激。
I'm a beginner programmer in Android and I guess this may not be the best practice but I have a list of news and categories. Each one with different parameters that go to another Activities.I wonder if anyone could be so kind and offer a workaround for this.
nuList = (ListView)findViewById(R.id.list2);
adapter1 = new CategsAdapter(UhoraYCategs.this, names);
nuList.setAdapter(adapter1);
Utility.setListViewHeightBasedOnChildren(nuList);
list = (ListView)findViewById(android.R.id.list);
adapter = new LazyAdapter(UhoraYCategs.this, imgs, titles, catg);
list.setAdapter(adapter);
Utility.setListViewHeightBasedOnChildren(list);
and the listeners for each one
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(this, UhoraList.class);
i.putExtra("categoria", names[position]);
i.putExtra("xml", urls[position]);
startActivity(i);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(this, NewsIntentPave.class);
i.putExtra("tit", (messages.get(position).getTitle()).toString());
i.putExtra("descric",(messages.get(position).getDescription()).toString());
i.putExtra("fecha", (messages.get(position).getDate()).toString());
i.putExtra("foto", (messages.get(position).getFoto()).toString());
i.putExtra("url", (messages.get(position).getLink()).toString());
i.putExtra("banner", "uhora");
startActivity(i);
}
How could I relate each listener with each list?. any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 CursorAdapter 中创建视图时,根据需要调用 view.setTag("List A") 或 "List B",然后在侦听器方法中
UPDATE
一种更简单的方法是使用父控件的 id switch 语句
When creating your views in the CursorAdapter call view.setTag("List A") or "List B" as appropriate then in your listener method
UPDATE
A simpler way is to use the id of the parent control in a switch statement
我终于成功了,我不知道这是否是最好的方法,但它确实有效。
基本上在“onCreate”上将 setOnItemClickListener 添加到一个列表视图。
并与常规侦听器一起使用另一个列表视图。
非常感谢梅林提供的所有帮助。
I finally managed to do it, idk if it's the best way but it works.
Basically on the 'onCreate' added the setOnItemClickListener to one Listview.
And worked the other Listview with the regular listener.
Thanks a lot to Merlin for all the help.