2012-02-09 10 views

答えて

0

3つのリストビューでフラグメントを作成したいのですか?

YourFragment extends Fragmentを書くだけです。レイアウトには3つのリストビューが含まれています。

ListActivityのようにListFragmentは役に立たないと思います。

0

3つのListFragmentsが必要な場合は、このようになります。

main.xml:

<?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。

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); 
    } 
} 

役に立てば幸い!

関連する問題