2012-02-09 2 views

답변

0

3 개의 listview로 조각을 만들겠습니까?

YourFragment extends Fragment를 작성하십시오. 레이아웃에는 3 개의 listview가 있습니다.

이 상황에서 ListFragment는 쓸모가 없다고 생각합니다. ListActivity와 같습니다.

0

세 개의 ListFragments가 필요하다면 다음과 같이됩니다. 다음

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="3dp"> 

<fragment class="com.fragtest.Fragment1" 
    android:id="@+id/fragment1" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 

<fragment class="com.fragtest.Fragment2" 
    android:id="@+id/fragment2" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 

<fragment class="com.fragtest.Fragment3" 
    android:id="@+id/fragment3" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 
</LinearLayout> 

각 단편에 대한 XML :

main.xml에

.

fragment1.xml : 마지막으로 다음

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:drawSelectorOnTop="false" /> 
</LinearLayout> 

그리고 몇 가지 코드가 모두 함께 걸어합니다. 귀하의 주요 활동 :

public class ListFragmentExampleActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 
} 

그리고 목록을 채우는 각 조각에 대한 클래스 ... Fragment1.java : 도움이

public class JobFragment extends ListFragment { 

    private ScheduleDBAdapter mDBHelper; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     return inflater.inflate(R.layout.fragment1, container, false); 
    } 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     mDBHelper = new ScheduleDBAdapter(getActivity()); 
     mDBHelper.open(); 
     fillData(); 
    } 

    private void fillData() { 
     Cursor jobsCursor = mDBHelper.fetchAllJobs(); 
     getActivity().startManagingCursor(jobsCursor); 
     String[] from = new String[] { ScheduleDBAdapter.JOB_NUMBER, 
       ScheduleDBAdapter.JOB_PART }; 
     int[] to = new int[] { R.id.ListItem1, R.id.ListItem2 }; 
     SimpleCursorAdapter jobs = new SimpleCursorAdapter(getActivity(), 
       R.layout.listlayoutdouble, jobsCursor, from, to); 
     setListAdapter(jobs); 
    } 
} 

희망!

관련 문제