我用自定义适配器创建了一个常规列表视图,一切都很好。它显示了对象的名称(正是我想要的)。我也想展示其他一些信息。所以从我的研究中,我发现我需要创建一个自定义文本视图来处理这个需求。我试图做一个基本的,我改变背景颜色为黑色以外的任何东西,但不工作。我真的不知道为什么。下面是自定义适配器代码:安卓在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