I have a listView that is being populated by ArrayAdapter. I want a different layout for first Row/Cell of the ListView.
Also I found a very similar question but cldnt add headerView in my code Android different Row layout only for first row in BaseAdapter
I have implemented that using the code below:
public class ActorAdapter extends ArrayAdapter<Actors> {
ArrayList<Actors> actorList;
LayoutInflater vi;
int Resource1;
int Resource2;
ViewHolder holder;
public ActorAdapter(Context context, int resource, ArrayList<Actors> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource1 = resource;
Resource2 = resource;
actorList = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
holder = new ViewHolder();
if (position == 0){
v = vi.inflate(R.layout.first_item, null);
holder.imageview = (ImageView) v.findViewById(R.id.thumb);
holder.tvName = (TextView) v.findViewById(R.id.title);
}
else{
v = vi.inflate(R.layout.list_item, null);
holder.imageview = (ImageView) v.findViewById(R.id.thumb);
holder.tvName = (TextView) v.findViewById(R.id.title);
}
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.imageview.setImageResource(R.drawable.ic_launcher);
Picasso.with(getContext()).load(actorList.get(position).getImage()).into(holder.imageview);
String postTitle = actorList.get(position).getName();
Spanned deTitle = Html.fromHtml(Html.fromHtml((String) postTitle).toString());
holder.tvName.setText(String.valueOf(deTitle));
return v;
}
The problem is, My list initially fetches 10 items. After that I load More articles as the user scrolls down. Now the 11th item of the list also gets layout of 1st item.
Also, when i scroll back to the top, the layout of first item is changed to that of other list items.
Please help with this.