Reputation: 4981
I have a ListView that contains 1 image+2 texts + 1 image on a line. This is my xml for listview :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="20dp"
android:gravity="left|center"
android:layout_width="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="@color/list_bg"
>
<ImageView
android:id="@+id/avatar"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_toRightOf="@+id/avatar"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
>
<TextView android:id="@+id/listitem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textColor="@drawable/textblack_selected"
android:textSize="18dp"
android:textStyle="bold"
/>
<TextView android:id="@+id/listitem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/textorange_selected"
/>
</LinearLayout>
<ImageView
android:id="@+id/arrowImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_alignParentRight="true"
android:src="@drawable/arrow_selector"/>
</RelativeLayout>
I need to remove the last image(the arrow) from the last line. In my adapter I tried to use this :
if (position == 4) lastimg.setImageResource(0);
but nothing changed.Here is my adapter:
public class UserItemAdapter extends ArrayAdapter < UserRecord > {
private ArrayList < UserRecord > users;
public UserItemAdapter(Context context, int textViewResourceId, ArrayList < UserRecord > users) {
super(context, textViewResourceId, users);
this.users = users;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.mainmenurowlist, null);
}
UserRecord user = users.get(position);
if (user != null) {
TextView listitem1 = (TextView) v.findViewById(R.id.listitem1);
TextView listitem2 = (TextView) v.findViewById(R.id.listitem2);
if (listitem1 != null) {
listitem1.setText(user.listitem1);
}
if (listitem2 != null) {
listitem2.setText(user.listitem2);
}
}
firstimg = (ImageView) v.findViewById(R.id.avatar);
lastimg = (ImageView) v.findViewById(R.id.arrowImage);
firstimg.setImageResource(FirstImage[position]);
if (position == 4) {
lastimg.setImageResource(0);
System.out.println("Exit!!");
}
return v;
}
}
public class UserRecord {
public String listitem1;
public String listitem2;
public UserRecord(String listitem1, String listitem2) {
this.listitem1 = listitem1;
this.listitem2 = listitem2;
}
}
}
Has anyone any idea how can I solve this? Thanks in advance.
Upvotes: 0
Views: 208
Reputation: 4968
try like this
if(position == (data_id.size()-1))
{
lastimg.setVisibility(View.INVISIBLE);
}
here data_id is just an array list
or try as below
if(position == 4)
{
lastimg.setVisibility(View.INVISIBLE);
}
both are to be same
Upvotes: 2
Reputation: 7605
use this way in getView() method
if((users.size()-1)==position){
// do here your stuff what u want on last item of listview
}else{
// do here your stuff what u want on each item of listview except last item
}
Upvotes: 0