Android 如何从TabHost中当前选项卡上的EditText获取值
我有tabhost,它有4个选项卡:细节、材质、腿部和其他照片。我已经成功地显示了所有这些。现在我的问题是,当我点击右角的菜单(在OnOptions ItemSelected上)时,如何从细节选项卡上的EditText获取文本值?这是我的密码:Android 如何从TabHost中当前选项卡上的EditText获取值,android,get,android-edittext,android-tabhost,Android,Get,Android Edittext,Android Tabhost,我有tabhost,它有4个选项卡:细节、材质、腿部和其他照片。我已经成功地显示了所有这些。现在我的问题是,当我点击右角的菜单(在OnOptions ItemSelected上)时,如何从细节选项卡上的EditText获取文本值?这是我的密码: public class ViewDetailItem extends TabActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(
public class ViewDetailItem extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_detail_item);
Global.ViewDetailItem=this;
Bundle param=getIntent().getExtras();
String tseparate=(String) param.get("tseparate");
String tgroup=(String) param.get("tgroup");
String titemcode=(String) param.get("titemcode");
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, DetailTab.class);
intent.putExtra("titemcode", titemcode);
intent.putExtra("tseparate", tseparate);
intent.putExtra("tgroup", tgroup);
spec = tabHost.newTabSpec("detail").setIndicator("Detail Item",res.getDrawable(R.layout.activity_tab_detail)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MaterialTab.class);
intent.putExtra("titemcode", titemcode);
intent.putExtra("tseparate", tseparate);
intent.putExtra("tgroup", tgroup);
spec = tabHost.newTabSpec("material").setIndicator("Mat Color",res.getDrawable(R.layout.activity_tab_materialcolor)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, LegTab.class);
intent.putExtra("titemcode", titemcode);
intent.putExtra("tseparate", tseparate);
intent.putExtra("tgroup", tgroup);
spec = tabHost.newTabSpec("leg").setIndicator("Leg Color",res.getDrawable(R.layout.activity_tab_legcolor)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, OtherPhotoTab.class);
intent.putExtra("titemcode", titemcode);
intent.putExtra("tseparate", tseparate);
intent.putExtra("tgroup", tgroup);
spec = tabHost.newTabSpec("other").setIndicator("Other Photos",res.getDrawable(R.layout.activity_tab_legcolor)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menudetailitem, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menuaddtocontainer:
// here is the code
// how to get value from edittext (id: EdtQty)on DetailTab
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
看一看这个使函数返回你的文本:如果你需要更多帮助,告诉我,我将用代码创建一个答案你有什么错误?等等,我想我犯了一个小错误,让我再试一次,我刚刚用答案1应用了,这里是我的源代码: