0

我設置一個列表適配器如下,如果我只是改變lv_layout simple_list_item_activated_1它根本不工作。如何覆蓋或添加自定義佈局android.R.layout.simple_list_item_activated_1

有什麼想法?

謝謝!

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(
      getActivity(), 
      android.R.layout.simple_list_item_activated_1, 
      android.R.id.text1, 
      DummyContent.ITEMS)); 
} 

如何將我的自定義佈局稱爲lv_layout到該適配器?

這是我的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:id="@+id/lv_layout" 

    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dp" 
     android:paddingRight="10dp" 
     android:paddingBottom="10dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/size" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="12sp" /> 

     <TextView 
      android:id="@+id/resolution" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="12sp" /> 

    </LinearLayout> 

</LinearLayout> 

回答

0

android.R.*是Android的內部資源。

要使用自己的佈局從res/layout/跳過Android的前綴:

R.layout.lv_layout 

也是一樣的IDS(如果你想知道)。

1

爲什麼你想使用setlistadapter呢?在這種情況下,您也必須創建自定義適配器,因爲serlistapater只會更新自定義佈局的textview部分,而其餘部分將忽略哪個idont認爲您想要的。所以 1.創建一個customadapter 2.override其getview 3.將適配器設置爲您的自定義佈局。 乾杯