2016-12-09 1 views
0

TabHost를 사용하여 2 개의 탭을 설정했습니다. 두 탭 모두 listview가 있습니다. 내가 각 항목을 클릭하면 항목을 클릭하면 작업이 완료되고, 내가 가지고있는 문제는 탭 2에 표시된 업데이트를 위해 응용 프로그램을 다시로드해야한다는 것입니다. 그래서 내가 원하는 것은 열 때입니다 탭은 각 열 때마다 탭에 대해 새로 고쳐집니다. 레이아웃을 얻으려면 필자의 탭 XML에 포함시킨다.Tab refresh (TabHost)

MainActivity에서 내 어댑터가 설정되었고 훌륭하게 작동했지만이 문제는 TabHost를 추가 한 이후에만 발생합니다.

  // My contentMain 
       <LinearLayout 
       android:id="@+id/tab1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <include 
        android:id="@+id/Onglet1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        layout="@layout/layouttab1" /> 

      </LinearLayout> 


      // My adapter 
      ArrayAdapter<Store1> adapter = new MyTitleAdapter(); 
      ListView myList = (ListView) findViewById(R.id.ListView); 
      adapterTitle.notifyDataSetChanged(); 
      myList.setAdapter(adapter); 


    TabHost.TabSpec spec = host.newTabSpec("Tab One"); 
    spec.setContent(R.id.tab1); 

    spec.setIndicator("First Tab"); 
    host.addTab(spec); 

    TabHost host = (TabHost)findViewById(R.id.tabHost); 
    host.setup(); 

    spec = host.newTabSpec("Tab Two"); 
    spec.setContent(R.id.tab2); 
    spec.setIndicator("Secong Tab"); 
    //host.setOnTabChangedListener(); 
    host.addTab(spec); 
+0

addontabselectedlistener() –

답변

0

당신이 당신의 어댑터에 전화 목록보기에

public void refreshWishlistAdapter() { 
itemList.clear(); 
itemList.addAll(dbHelper.getallWishlistItems()); 
itemsAdapter.notifyDataSetChanged(); 
} 
+0

어댑터를 추가 했으므로 작동하지 않습니다. tabHost와 함께 – user3175140

+0

은 tab1과 tab2에 대해 (조각 또는 acivity) 무엇을 사용 ??? –

+0

그렇지 않으면 전체 코드를 여기에 입력하십시오. –

0

사용 조각에서이 방법을 한 가지 방법 (자신에 의해 그것을 만들을) 항목을 추가 할 때, 그래서 당신은 조각이 방법을 전환 할 때 다음을 실행합니다.

private boolean isShown = false; 

@Override 
public void setUserVisibleHint(boolean isVisibleToUser) { 
    super.setUserVisibleHint(isVisibleToUser); 
    if (getView() != null) { 
     isShown = true; 
     // fetchdata() show data when page is selected 
     fetchData(); 
    } else { 
     isShown = false; 
    } 
}