這是我的問題: 我已經有一個標籤應用程序。 在每個選項卡中我有一個列表列表到另一個列表,然後到一個屏幕與圖像,可點擊的文本等 在一個單詞中我有任務標籤內。鏈接標籤內的鏈接
問題 儘管長論壇和教程中尋求我仍然想不通女巫是做到這一點的最好pactice:開關活動insde標籤 或更改視圖。
這裏我的代碼
public class App extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable 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, Activity0.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("0").setIndicator("0",
res.getDrawable(R.drawable.ic_tab_0))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Activity1.class);
spec = tabHost.newTabSpec("1").setIndicator("1",
res.getDrawable(R.drawable.ic_tab_1))
.setContent(intent);
tabHost.addTab(spec);
然後我要切換活動 - 選項卡內(Activity0> Activity01)0
public class Activity0 extends Activity{
..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlist);
ListView l1 = (ListView) findViewById(R.id.ListView01);
l1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// Toast.makeText(getBaseContext(), "You clciked "+parentTypes.get(arg2).getLibelle(), Toast.LENGTH_LONG).show();
/*TODO database method */
TypeEvenement parent = parentTypes.get(arg2);
if (parent.getChildren().size()!=0)
{
Intent i = new Intent(TypeParentList.this, TypeChildList.class);
int id= new Long(parentTypes.get(arg2).getId()).intValue();
i.putExtra("typeid", id);
View view = lam.startActivity("TypeChildList",i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)).getDecorView();
setContentView(view);
然後再返回到本次活動從Activity01
public class Activity01 extends Activity{
tv.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(TypeChildList.this, Activity0.class);
LocalActivityManager lam = pa.getLocalActivityManager();
View view2 = lam.startActivity("Activity0",i).getDecorView();
setContentView(view2);
}
});
回去後我得到一個錯誤java.lang.IllegalStateException指定的子項已經有了一個ap的arent。您必須先調用子對象的父對象的removeView()。
我知道它來自我的看法,但我不知道如何解決它 那麼這是在一個選項卡中執行多個活動的最佳做法嗎?
請幫助需要
我已經完成了它,通過替換視圖,例如你喜歡的適配器 – superseed77 2010-07-29 13:00:52
樣本的任何機會都取代了嗎? – 2011-10-27 14:25:00