カスタムのArrayAdapterを作成してListを作成しました。これはgetView(int position、View v、ViewGroup parent)をオーバーライドします。Androidリスト+アダプターは最初のエントリだけを表示します
私はこのようにそれを使用する場合:
public class MyActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(adapter);
}
}
Everthingが正常に動作し、私のリストが正しくすべてのエントリが表示されます。
は今、私はこのようなXMLレイアウトの<のListView />、上の同じアダプタクラスを使用しようとします。それはリストの最初のエントリだけを示し
ListView lv = (ListView) v.findViewById(R.id.list);
MyAdapter a = new MyAdapter (lv.getContext(), R.layout.list_item, entries);
lv.setAdapter(a);
。
私はすでに項目を手動でadapter.add(entry.get(i))で追加しようとしました。 adapter.notifyDataSetChanged()を呼び出します。後で助けにならなかった。
E:ここではXMLレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1dp">
<TextView
android:id="@+id/bc_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="@+id/bc_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@drawable/title_gradient"/>
<TextView
android:id="@+id/bc_genre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:background="@drawable/location_gradient"
android:textColor="#ffffff"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="0.4"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp">
<ImageButton
android:id="@+id/bc_homepage"
android:src="@drawable/homepage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="loadWebsite"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
<ImageButton
android:id="@+id/bc_facebook"
android:src="@drawable/facebook"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="loadWebsite"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
<ImageButton
android:id="@+id/bc_myspace"
android:src="@drawable/myspace"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="loadWebsite"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
<ImageButton
android:id="@+id/bc_fav"
android:src="@drawable/d_attends"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="favBand"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
'getCount'を' return 1'として実装しましたか? – zapl
リストのXMLを貼り付けることはできますか?レイアウトサイズの問題かもしれません – njzk2
いいえ私はgetCountを上書きしないで、正しい数のエントリを返します。 – Dreiven