0

나는 그것을 짧고 요점을 지키려고 노력할 것이다. 나는이있는 ListView에 항목을 누를 때, 조각은 해당 선수의 데이터를 새로운 조각으로 대체되는 것을 enter image description hereFragmentTabsPager 호환성 라이브러리 예제를 사용할 때 어떤 내용을 탭 내에서 대체합니까?

어떻게 방법을 구현합니까 :

은 아래의 스크린 샷을 준수? FrameLayout tabcontent의 내용을 대체해야합니까? 그렇다면 ViewPager가 여전히 기능을 유지하는지 확인하려면 어떻게해야합니까?

"기본 활동"의 XML :

<TabHost 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0"/> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="0"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

</LinearLayout> 
</TabHost> 

그리고 이것은 onActivityCreated입니다 :

@Override 
    public void onActivityCreated(Bundle savedInstance) 
    { 
     super.onActivityCreated(savedInstance); 
     setHasOptionsMenu(true); 


     listView = (ListView)getActivity().findViewById(R.id.lv_federations); 
     listView.setVisibility(View.GONE); 
     if (savedInstance == null) 
     { 
      new PullFederationDataTask().execute(); 

     }  

     listView.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, 
        int position, long arg3) 
      { 
       // Replace Fragment 
      } 
     }); 
    } 

어떻게해야합니까?

답변

0

코드에서 onItemClickListener에있는 조각 대체에 대해서는 확실하지 않습니다. 동일한 문제로 고민하고 있으며 아직 적절한 해결책을 찾지 못했기 때문입니다.

ListFragment을 확장하여 플레이어 목록을 구현하는 경우 fragment transactions을 사용하는 플레이어의 세부 정보를 표시하는 새 조각으로 현재 조각을 바꿀 수 있습니다 (또는 새로운 활동을 시작할 수도 있지만 조각 트랜잭션 이 대답에서).

@Override 
public void onListItemClick (ListView l, View v, int position, long id) { 

    // Here I assume that the fragment containing the player details 
    // is called PlayerDetailFragment. 
    // The id of the item that was clicked is passed to the fragment's constructor. 
    Fragment newFragment = new PlayerDetailFragment(id); 
    FragmentTransaction ft = getFragmentManager().beginTransaction(); 

    // Replace whatever is in the fragment_container view with this fragment, 
    // and add the transaction to the back stack. 
    // android.R.id.content refers to the id of the root ViewGroup. 
    ft.replace(android.R.id.content, newFragment); 
    ft.addToBackStack(null); 

    // Commit the transaction 
    ft.commit();  
} 

당신은에 ListAdapter의 getItemId() 방법을 사용할 수 있습니다 :

당신이 조각의 생성자에 대한 인수로 클릭 한 목록 항목의 ID를 취하는 onListItemClick 방법의 새로운 조각을 만들 수 조각을 교체하려면 플레이어의 ID를 참조하십시오. ListView.setAdapter() 방법을 사용하여 ListView에 자신의 ListAdapter을 사용합니다. ListAdapter은이 목록을 뒷받침하는 데이터를 유지 관리하고 해당 데이터 세트의 항목을 나타 내기위한보기를 생성합니다. This 자습서에서는 ListView에 대해 ArrayAdapter을 직접 작성하는 방법을 설명합니다.

ListAdapter에서 getItemId() 메서드를 재정의하고 플레이어의 ID를 반환합니다. 그런 다음 PlayerDetailFragment은 ID를 사용하여 데이터베이스에서 데이터를 검색 할 수 있습니다.

ViewPager에 대한 경험이 없으므로 도와 드릴 수 없습니다.

관련 문제