我正在开发新的应用程序,我使用制表符视图作为父布局。我正在使用TabHost在我的应用程序中显示3个选项卡。这些选项卡中的每一个都有单独的包含ListView的Activity。这工作正常。当您单击ListView中的项目时,它当前会加载一个全新的活动全屏,而不会显示TabHost。我想在TabHost中加载这些活动。我想在列表视图中调用另一个活动后保留tabview。
感谢您的回复。这是我的代码,我需要你的帮助。
################ HelloTabWidget//此类显示带有3个选项卡的选项卡视图 - 客户,公司和城市。
public class HelloTabWidget extends TabActivity {
//public class HelloTabWidget extends ActivityGroup {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, CustomerTabView.class);
spec = tabHost
.newTabSpec("Customer")
.setIndicator("Customer",
res.getDrawable(R.drawable.ic_tab_Customer))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CompanyTabView.class);
spec = tabHost
.newTabSpec("Company")
.setIndicator("Company",
res.getDrawable(R.drawable.ic_tab_Company))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CityTabView.class);
spec = tabHost
.newTabSpec("City")
.setIndicator("City", res.getDrawable(R.drawable.ic_tab_City))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
################ CustomerTabView
//此类显示客户名称的列表视图。单击列表中的任何项目,它应打开客户详细信息页面,保持相同的选项卡视图。
public class CustomerTabView extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] category = getResources().getStringArray(
R.array.category_array);
setListAdapter(new ArrayAdapter<String>(this, R.drawable.list_items,
category));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Need this logic where I can retain the tab view and call new activity class for customerdetails view.
Intent intent;
intent = new Intent(CustomerTabView.this,
C_DetailActivity.class);
startActivity(intent);
finish();
}
});
}
}
################ C_DetailActivity
点击来自customertabview的任何项目,此活动类将获得显示客户详细信息的电话。
public class C_DetailActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Customer Details view");
setContentView(textview);
}
}
调用C_DetailActivity类后,选项卡视图消失。我想保留主标签视图。 所以需要这个逻辑,我可以保留选项卡视图并为customerdetails视图调用新的活动类
答案 0 :(得分:1)
ListView lv = (ListView) findViewById(R.id.myListView);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
LocalActivityManager manager = getLocalActivityManager();
String currentTag = tabHost.getCurrentTabTag();
manager.destroyActivity(currentTag, true);
manager.startActivity(currentTag, new Intent(this, newClass.class));
}
});
未经测试,但这样的事情应该有效。如果不是,我会帮你解决它。