单击前一个 ListView 上的某一行后,如何打开另一个 ListView?

发布于 2024-10-16 01:04:00 字数 434 浏览 1 评论 0原文

我想知道如何在单击前一个 ListView 上的某一行后打开另一个 ListView

Bee VOA reader 可能是一个很好的例子来了解我在说什么。

List A                          List B
DeskTop Development    --->     Buttons
                                TextView
                                ScrollBar
Mobile 
Graphic
Game

所以手机屏幕上有一个列表A,列表A中有很多主题 如果我点击其中一个主题,比如说桌面开发,那么整个 ListView 将从屏幕上滑出,并显示新的列表 B。

那么如何实施呢?

I want to know how to open another ListView after one of rows on the previous ListView has been clicked?

Bee VOA reader could be a good example to see what I'm talking about.

List A                          List B
DeskTop Development    --->     Buttons
                                TextView
                                ScrollBar
Mobile 
Graphic
Game

So there is one list A on the phone's screen, and there are many topics in the list A
If I clicked on one of the topic,let's say DeskTop Development, then the whole ListView
will be slided away from the screen and the new List B will be presented.

So how to implement it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤ぢ 2024-10-23 01:04:00

打开一个新的活动,同时传递适当的数据以显示正确的信息,是完成您正在做的事情的好方法。这是一个州列表的代码示例,该列表转到上一个列表中所选州的城市列表。第一个活动中的州列表视图将州名称发送到第二个活动中的城市列表视图,第二个活动显示该州的城市列表。

private ListView lv;
setContentView(R.layout.displaylayout);
lv = (ListView)findViewById(R.id.DisplayList);
lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {
                Intent myIntent = new Intent(view.getContext(), DisplayLocationsCities.class);
                myIntent.putExtra("state",lv.getItemAtPosition(position).toString());
                startActivityForResult(myIntent, 0);


              }
            });

///////////////////////后退按钮代码允许您返回到上一个列表(关闭需要在 onDestroy() 中关闭的任何内容):

this.backButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View view) {              

                  // equivalent of 'return'
                  finish();
              }
});

// /////////////////////动态添加项目到列表中:

String [] list = {"New York","Illinois","California","Wisconsin"};
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, list));

//////////////////////Extra信用:每个 listView 项目的布局 - R.layout.list_item(res/layout 文件夹中的 list_item.xml):

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:cacheColorHint="@android:color/transparent"
    android:textSize="12sp" android:textColor="#000000" android:textStyle="bold" android:gravity="center">
</TextView>

Opening a new Activity while passing the appropriate data to display the correct information is a good way to do what you're doing. This is a code example of a list of states which goes to a list of cities in the selected state from the previous list. The state listview from the first activity sends the name of the state to the city listview in second activity which displays a list of cities from that state.

private ListView lv;
setContentView(R.layout.displaylayout);
lv = (ListView)findViewById(R.id.DisplayList);
lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {
                Intent myIntent = new Intent(view.getContext(), DisplayLocationsCities.class);
                myIntent.putExtra("state",lv.getItemAtPosition(position).toString());
                startActivityForResult(myIntent, 0);


              }
            });

//////////////////////back button code allowing you to go back to the previous list (close anything that need to be closed in onDestroy()):

this.backButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View view) {              

                  // equivalent of 'return'
                  finish();
              }
});

//////////////////////adding items to your list dynamically:

String [] list = {"New York","Illinois","California","Wisconsin"};
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, list));

//////////////////////Extra Credit: Layout for each listView item - R.layout.list_item (list_item.xml in the res/layout folder):

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:cacheColorHint="@android:color/transparent"
    android:textSize="12sp" android:textColor="#000000" android:textStyle="bold" android:gravity="center">
</TextView>
风渺 2024-10-23 01:04:00

实现 onListItemClick() 方法,以便单击时启动一个新的 ListActivity。这样,菜单中的导航将更加容易,因为您将能够使用后退按钮。

Implement the onListItemClick() method so that on click it starts a new ListActivity. This way the navigation in the menu will be easier as you will be able to use the back button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文