我用自定義適配器創建了一個常規列表視圖,一切都很好。它顯示了對象的名稱(正是我想要的)。我也想展示其他一些信息。所以從我的研究中,我發現我需要創建一個自定義文本視圖來處理這個需求。我試圖做一個基本的,我改變背景顏色爲黑色以外的任何東西,但不工作。我真的不知道爲什麼。下面是自定義適配器代碼:安卓在ListView中的自定義TextView
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
if(arg1==null)
arg1 = layoutInflator.inflate(R.layout.simplerow ,arg2, false);
TextView name = (TextView)arg1.findViewById(android.R.id.text1);
name.setText(discountObjectArray[arg0].name);
return arg1;
}
,這裏是很簡單的自定義的TextView在simplerow.xml代碼:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textDirection="rtl"
android:background="@color/thankYouLabelColor">
</TextView>
與於R android.R.layout.simple_list_item_1的簡單變化.layout.simplerow logcat在第49行顯示錯誤:
name.setText(discountObjectArray[arg0].name);
任何想法爲什麼這不起作用?
'TextView的名稱=( TextView中) arg1.findViewById(R.id.customTextView);'id是'customTextView'。你指的是android框架中的一個。 – Raghunandan
在49行發佈logcat錯誤 – Suji