我想要綁定數組列表到我的列表視圖。我無法理解如何將對象值(如其名稱)與列表中顯示的列表項XML值相關聯。構造函數ArrayAdapter <String>(MainActivity.ReadJSONResult,int,List <BeerData>)未定義
試圖從我的數組列表項目添加到列表視圖:
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.list_item, beerList);
lv.setAdapter(arrayAdapter);
我R.layout.list_item文件看起來像這樣:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
我的全主文件可以在這裏查看看我怎麼做我的數組列表:
您正在創建一個 ArrayAdapter,但它傳遞BeerData對象,而不是的字符串。 –
創建的字符串數組並把它傳遞到適配器,或進行自定義適配器 – abhi