目前我在Android应用程序中工作,使用Tabbar创建五个选项卡,如1,2,3,4和5.第一个选项卡使用ListActivity创建ListView,当我从ListView中选择ListItem时,ListItem值变为3rd选项卡,我也正在获得第三个选项卡中的值,但问题是值从第一个选项卡传递到第三个选项卡,在第一个选项卡仅选中时,但我想要第三个选项卡选择。 如何解决这个问题?请帮助我。
先谢谢
供您参考的源代码:
第一个标签:
@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
public class 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();
}
}
}
答案 0 :(得分:0)
您是否查看了this post底部的示例应用程序?
更具体地说:
如果所有其他方法都失败了,您还应该能够使用tabHost.setCurrentTab(int tabIndex)
手动更改所选标签。