0

ロゴを含むヘッダーが必要です。次に、リスト ビューです。しかし、私は両方を画面に表示するのに苦労しています。ヘッダーのみまたはリストビューのみを取得します。誰でもここに光を当ててください。これが私のファイルです。

// Grammar_sections.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grammar_sections);
   Intent i = getIntent();

    module_id =i.getStringExtra("module_id");

    TestAdapter mDbHelper = new TestAdapter(getBaseContext());        
    mDbHelper.open();

    ArrayList<String> testdata = mDbHelper.getAllSections(module_id);

    for(String t : testdata )
    {
        //Log.d("out", t.toString());
    }

    mDbHelper.close();


    m_listview = (ListView) findViewById(R.id.list);

    if(m_listview != null)
    {
        Log.i("check","yup");
    }
    else
    {
        Log.i("check","nope");
    }


    ArrayAdapter<String> adapter =
      new ArrayAdapter<String>(this,R.layout.grammar_sections , R.id.list_item, testdata);

     m_listview.setAdapter(adapter);

grammar_sections.xml

  // grammar_sections.xml

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >

<!--  Header  Starts-->
    <LinearLayout android:id="@+id/header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@layout/header_gradient"
            android:paddingTop="5dip"
            android:paddingBottom="5dip">
            <!-- Logo Start-->
            <ImageView android:src="@drawable/logo_icon"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:layout_marginLeft="10dip"/>

            <ImageView android:src="@drawable/logo_text"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:layout_marginLeft="10dip"/>


            <!-- Logo Ends -->
       </LinearLayout>
   <!--  Header Ends -->



<TextView
    android:id="@+id/list_item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:padding="16dip"
    android:typeface="sans"
    android:textSize="16dip"
    />

    <ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="#b5b5b5"
    android:dividerHeight="1dp"
     />

 </RelativeLayout>
4

3 に答える 3

0

動作するサンプル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:background="@color/background"
    android:orientation="vertical" >

    <include layout="@layout/header" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="@color/white"
        android:choiceMode="singleChoice"
        android:divider="@color/blue_vdark"
        android:dividerHeight="1dp" />

</LinearLayout>

インクルードをカスタムに置き換えるか、またはその下に追加することがViewできLayoutますListView
このコードを自分のコードと比較してみてください。</RelativeLayout>また、xmlファイルの最後にタグが表示されません。

于 2012-08-28T11:58:42.810 に答える
0

あなたのコードから、

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.grammar_sections , R.id.list_item, testdata);

同じgrammar_sections.xmlファイルをArrayAdapterに渡しています。代わりに、リスト項目を含む別のxmlレイアウトファイルを作成し、このxmlレイアウトファイルをArrayAdapterコンストラクターに渡します..

于 2012-08-28T11:22:54.023 に答える
0

ListViewメソッドaddHeaderViewがあります。ドキュメントが言うように:

Add a fixed view to appear at the top of the list.

したがって、単にあなたviewを作成し、それを介して取得しますinflater。次に、それをに追加しますListView

于 2012-08-28T11:21:57.363 に答える