目前我在 Android 应用程序中工作,使用 Tabbar 创建五个选项卡,如 1、2、3、4 和 5。第一个选项卡使用 ListActivity 创建 ListView,当我从 ListView 中选择 ListItem 时,ListItem 值转到第三个选项卡,并且我在第三个选项卡中得到了很好的值,但问题是从第一个选项卡到第三个选项卡的值传递,当时只选择了第一个选项卡,但我想选择第三个选项卡。如何解决这个问题,请帮助我。
提前致谢
源代码供您参考:
第一个标签:
@Override
protected void onListItemClick(ListView l, final View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String SelectedItem = l.getItemAtPosition(position).toString();
System.out.println("Selected Item: "+ SelectedItem);
System.out.println("position Item: "+ position);
String SelectedPhoneNumber = phoneNumber.get(position);
System.out.println("SelectedPhoneNumber " + SelectedPhoneNumber);
// Using TabGroupActivity, so
Intent i = new Intent(getParent(), 3rdTab.class);
i.putExtra("DestinationNumber", SelectedPhoneNumber);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("Sample", i);
}
TabGroupActivity.java
公共类 TabGroupActivity 扩展 ActivityGroup {
private ArrayList<String> mIdList; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (mIdList == null) mIdList = new ArrayList<String>(); } @Override public void finishFromChild(Activity child) { LocalActivityManager manager = getLocalActivityManager(); int index = mIdList.size()-1; if (index < 1) { finish(); return; } manager.destroyActivity(mIdList.get(index), true); mIdList.remove(index); index--; String lastId = mIdList.get(index); Intent lastIntent = manager.getActivity(lastId).getIntent(); Window newWindow = manager.startActivity(lastId, lastIntent); setContentView(newWindow.getDecorView()); } public void startChildActivity(String Id, Intent intent) { Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); if (window != null) { mIdList.add(Id); setContentView(window.getDecorView()); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR return true; } return super.onKeyDown(keyCode, event); } /** * Overrides the default implementation for KeyEvent.KEYCODE_BACK * so that all systems call onBackPressed(). */ @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { onBackPressed(); return true; } return super.onKeyUp(keyCode, event); } @Override public void onBackPressed () { int length = mIdList.size(); if ( length > 1) { Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1)); current.finish(); } } }