I am trying to change the border around the listview item, unfortunately I am getting null reference errors when I try and reference the layout to change the border. layout.setBackgroundResource(R.drawable.border_purchased);
causes the null reference. Any idea where I am missing a method/concept?
Part of adapter
@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;
}
Layout:
<?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>
you don't pass the parent when inflating the view: