我正在尝试更改 listview 项目周围的边框,不幸的是,当我尝试引用布局以更改边框时,我遇到了空引用错误。layout.setBackgroundResource(R.drawable.border_purchased);
导致空引用。知道我在哪里缺少方法/概念吗?
适配器的一部分
@Override
public View getItemView(Item object, View v, ViewGroup parent) {
if (v == null)
{
v = View.inflate(getContext(), R.layout.listview_itempage, null);
}
super.getItemView(object, v, parent);
TextView itemTextView = (TextView) v.findViewById(R.id.textViewItemName);
itemTextView.setText(object.getItemName());
if(object.getPurchasedStatus() == true)
{
RelativeLayout layout = (RelativeLayout) v.findViewById(R.id.itemListBorder);
layout.setBackgroundResource(R.drawable.border_purchased);
}
if(object.getRejectReason() != null)
{
RelativeLayout layout = (RelativeLayout) v.findViewById(R.id.itemListBorder);
layout.setBackgroundResource(R.drawable.border_reject);
}
return v;
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:orientation="vertical"
android:id="@+id/itemListBorder"
android:background="@drawable/border_main"
>
<com.parse.ParseImageView
android:id="@+id/imgStore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView
android:id="@+id/textViewStoreTitle"
android:textSize="30dp"
android:textColor="#FFFFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/textViewStoreItemCount"
android:textSize="15dp"
android:textColor="#FFFFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="0 items"
android:layout_below="@id/textViewStoreTitle"/>
</RelativeLayout>
</LinearLayout>