2010-04-04 49 views
2

我想点击列表视图“A”的一个项目之后,显示另一个列表视图“B”陆续列表视图“B”。我在Android 1.6项目中使用onListItemClick事件。如何显示点击列表视图“A”

public void onListItemClick(ListView parent, View v, int position, long id) { 
    Toast.makeText(this, 
     "You have selected " + lv_arr[position], 
     Toast.LENGTH_SHORT).show(); 
} 

如何编码?

回答

1

如果你想留在同一个活动和布局,你可以使用一个ViewSwitcher,这是专为两个视图之间翻转。

不过我强烈建议点击通过一个Intent触发一个新的本地活动。这将有一个包含你的第二个ListView的新布局。这是因为用户会期望点击并且显示器发生了显着变化,按下后退按钮会将它们带回应用程序中的原始位置。作为一般规则,任何改变应用程序中概念位置的用户操作都应该伴随着一项活动更改。

0

如何尝试ExpandableListView。当你点击组视图时,它将展开以显示子视图。它有一个很好的BaseExpandableListAdapter。

0

比如我打电话使用意图的新活动,添加了这种方式填充值...

@Override 
    public void onListItemClick(ListView parent, View v, int position, long id) { 
     Intent lancon = new Intent(this, viewContact.class); 
     //lancon.putExtra("id", id); 
     //or 
     c.moveToPosition(position); 
     id = c.getInt(0); 
     c.close(); 
     lancon.putExtra("id", id); 
     this.startActivity(lancon); 
     finish(); 
    } 

然后在其他类onCreate方法我称之为:

this._id = this.getIntent().getLongExtra("id", 0); 
+0

对不起,我的不便回复。我没有在AndroidMainfest.xml中添加这个列表活动。 – soclose 2010-04-19 03:46:30

1

我能看到列表视图加入

<activity android:name=".WhiteListView"/> 

在AndroidMainfest.xml中。

相关问题