I build a list with listfragment and custom adapter !! i want 25th row fill with diffrent view !!! and my code works in first time the view showed and when scroll up the list and row out the screen get FC ! while if i comment this line==> if(row == null){ the code works good and no problem but, there are many items in the list and list is slow because because the list is not optimized
public class MyListAdapter extends ArrayAdapter{
Context myContext;
private ArrayList mList;
public MyListAdapter(Context context, int textViewResourceId,ArrayList list) {
super(context, textViewResourceId, list);
myContext = context;
list=this.mList;
}
@Override
public View getView( final int position, View convertView, ViewGroup parent) {
View row=convertView;
if(row == null){
if(position!=20)
{
LayoutInflater inflater = (LayoutInflater)myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.row, parent, false);
ViewHolder holder = new ViewHolder();
// holders
holder.txt_name = (TextView)row.findViewById(R.id.txt_name);
holder.txt_sms = (TextView)row.findViewById(R.id.txt_sms);
holder.txt_vote = (TextView)row.findViewById(R.id.txt_vote);
holder.btn_favorite=(ImageView)row.findViewById(R.id.btn_favorite);
holder.btn_send=(Button)row.findViewById(R.id.btn_send);
row.setTag(holder);
}
else{
LayoutInflater inflater = (LayoutInflater)myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.row2, parent, false);
}
}
if(position!=20)
{
ViewHolder holder = (ViewHolder)row.getTag();
holder.txt_sms.setText(mysms.get(position).gettext());
holder.txt_name.setText(mysms.get(position).getname());
holder.txt_vote.setText(mysms.get(position).getVotenum()+"");
holder.btn_favorite.setImageResource(R.drawable.icon);
holder.btn_send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
}
return row;
}
}
static class ViewHolder {
TextView txt_sms;
TextView txt_name;
TextView txt_vote;
ImageView btn_favorite;
Button btn_send;
}