2012-07-10 81 views
0

我有一個使用標籤主機制作的應用程序。 我需要點擊時刷新我的列表視圖(第二個標籤)。 這種觀點包含DB數據,很明顯,它需要在整個應用程序,我做更新,插入,刪除要始終保持最新狀態(因爲... 我哪有?Android:更改標籤必須刷新我的列表視圖db

這是中的onCreate通過標籤

super.onCreate(savedInstanceState); 
    setContentView(R.layout.bookmarks); 
    final Database info=new Database(this); 
    final Timer t = new Timer(); 
    info.open(); 
    final Cursor data=info.getData(); 
    final ListView listView1 = (ListView) findViewById(R.id.list_mia); 
    String[] from = new String[] {"contenuto"}; 
    int[] to = new int[] { android.R.id.text1 }; 
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1, data, from, to); 
    listView1.setAdapter(adapter); 

這就是標籤類稱爲類(以下簡稱「牽連類是書籤)

super.onCreate(savedInstanceState); 
    setContentView(R.layout.tabs); 
    TabHost tabHost = getTabHost(); 
    // Tab per lettore 
    TabSpec lettoretab = tabHost.newTabSpec("Lettore"); 
    lettoretab.setIndicator("Lettore", getResources().getDrawable(R.drawable.lettore)); 
    Intent lettoreIntent = new Intent(this, Lettore.class); 
    lettoretab.setContent(lettoreIntent); 
    // Tab per bookmarks 
    TabSpec bookmarkstab = tabHost.newTabSpec("Bookmarks"); 
    bookmarkstab.setIndicator("Bookmarks", getResources().getDrawable(R.drawable.bookmarks)); 
    Intent bookmarksIntent = new Intent(this, Bookmarks.class); 
    bookmarkstab.setContent(bookmarksIntent); 
    // Tab per create 
    TabSpec createtabs = tabHost.newTabSpec("Create"); 
    createtabs.setIndicator("Create", getResources().getDrawable(R.drawable.create)); 
    Intent createIntent = new Intent(this, Create.class); 
    createtabs.setContent(createIntent); 
    // Tab per feed 
    TabSpec feedtabs = tabHost.newTabSpec("Feed"); 
    feedtabs.setIndicator("Feed", getResources().getDrawable(R.drawable.feed)); 
    Intent feedIntent = new Intent(this, Feeds.class); 
    feedtabs.setContent(feedIntent); 
    // Tab per actionmobileapp 
    TabSpec actionmobileapptabs = tabHost.newTabSpec("App"); 
    actionmobileapptabs.setIndicator("App", getResources().getDrawable(R.drawable.actionmobileapp)); 
    Intent actionmobileappIntent = new Intent(this, Actionmobileapp.class); 
    actionmobileapptabs.setContent(actionmobileappIntent); 
    // Aggiungo i tabs 
    tabHost.addTab(lettoretab); 
    tabHost.addTab(bookmarkstab); 
    tabHost.addTab(createtabs); 
    tabHost.addTab(feedtabs); 
    tabHost.addTab(actionmobileapptabs); 

我已經嘗試過召回的onResume的代碼,但沒有成功...

回答

1
TabHost tabHost = getTabHost(); 
      Intent intent = new Intent(this, c); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 
      View tabIndicator = LayoutInflater.from(this).inflate(
        R.layout.tab_indicator, getTabWidget(), false); 
      TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
      title.setText(labelId); 
      ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
      icon.setImageResource(drawableId); 

      spec.setIndicator(tabIndicator); 
      spec.setContent(intent); 
      tabHost.addTab(spec); 

在TabActivity類addTab內添加此()。

感謝....

+0

抱歉,但我不完全明白你的意思:我使用Tab類編輯了我的問題 – Zak 2012-07-10 09:40:44

+1

請在TabActivity類的addTab()中添加intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)。 – user4232 2012-07-10 09:42:12

+0

問題未解決:-( – Zak 2012-07-10 09:50:23

0

使「adpater」變市民「活動」,並在onResume調用此METT adapter.swapCursor(c)這裏c是新更新的光標。之後不要忘記撥打notifyDataSetChanged()