点击列表视图“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();
}
如何编码?
答案 0 :(得分:1)
如果您希望保持相同的活动和布局,可以使用ViewSwitcher,这是专为在两个视图之间翻转而设计的。
但是我强烈建议点击通过Intent触发新的本地活动。这将有一个包含第二个ListView的新布局。这是因为用户希望点击并显示显着变化,按下后退按钮将使他们回到应用程序中的原始位置。作为一般规则,任何更改应用程序中概念位置的用户操作都应伴随活动更改。
答案 1 :(得分:1)
我可以通过添加
来查看列表视图<activity android:name=".WhiteListView"/>
AndroidManifest.xml中的。
答案 2 :(得分:0)
试试ExpandableListView怎么样?当您单击组视图时,它会展开以显示子视图。它有一个很好的BaseExpandableListAdapter。
答案 3 :(得分:0)
例如,我使用Intents调用一个新活动,以这种方式添加打包值...
@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);