タブビューを親レイアウトとして使用している新しいアプリケーションを開発しています。TabHost を使用して、アプリケーション内に 3 つのタブを表示しています。これらの各タブには、ListView を含む個別のアクティビティがあります。これはうまくいっています。ListView 内のアイテムをクリックすると、現在、TabHost を離れて新しいアクティビティのフルスクリーンが読み込まれます。これらのアクティビティを TabHost 内にロードしたいと思います。リストビューから別のアクティビティを呼び出した後、タブビューを保持したい。
お二方、ご回答ありがとうございます。これがあなたの助けが必要な私のコードです。
################HelloTabWidget//このクラスは、Customer、Company、City の 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 ビューの新しいアクティビティ クラスを呼び出すことができるこのロジックが必要です