如何显示另一个列表视图“B”单击列表视图“A”后;
我想在单击列表视图“A”的项目后显示另一个列表视图“B”。我在Android 1.6项目中使用onListItemClick事件。
public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this,
"You have selected " + lv_arr[position],
Toast.LENGTH_SHORT).show();
}
如何编码呢?
I'd like to show another List View 'B' after clicking a item of List View 'A'. I use onListItemClick event in Android 1.6 project.
public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this,
"You have selected " + lv_arr[position],
Toast.LENGTH_SHORT).show();
}
how to code it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想保持相同的 Activity 和布局,您可以使用 ViewSwitcher,它是为两个视图之间的翻转而设计的。
不过,我强烈建议点击通过 Intent 触发新的本地 Activity。这将有一个包含第二个 ListView 的新布局。这是因为用户会期望单击后显示会发生显着变化,按下后退按钮会将他们带回到应用程序中的原始位置。作为一般规则,任何更改应用程序中概念位置的用户操作都应伴随活动更改。
If you want to stay on the same Activity and layout you could use a ViewSwitcher, which is designed for flipping between two views.
However I would strongly suggest that the click triggers a new local Activity via an Intent. This will have a new Layout containing your second ListView. This is because users will expect that having clicked and had the display significantly change, that pressing the back button will take them back to the original location in the app. As a general rule, any user action that changes the conceptual location in the application should be accompanied by an Activity change.
我可以通过添加 AndroidMainfest.xml 来查看列表视图
。
I could see the List View by adding
in AndroidMainfest.xml.
尝试一下 ExpandableListView 怎么样。当您单击组视图时,它会展开以显示子视图。它有一个很好的 BaseExpandableListAdapter。
How about try ExpandableListView. When you click on the groupview it expands to show childviews. It has a nice BaseExpandableListAdapter.
例如,我使用 Intents 调用一个新活动,并以这种方式添加打包值...
然后在另一个类的 onCreate 方法中我调用:
For example I call a new activity using Intents, with packed values added this way...
Then in the other class onCreate method I call: