0

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;


    }
Saeid Sds
  • 1
  • 1
  • good job.. but list view is recycling every time thats why you face this issue... for that you have to set focus false to every item of row file. and also add tag to every item.... check this ans and get idea... http://stackoverflow.com/a/10558101/1168654 – Dhaval Parmar Apr 15 '13 at 12:42
  • You are trying to make multiple type row `ListView` and here is how to do it, its pretty straight forward and easy: http://stackoverflow.com/questions/4777272/android-listview-with-different-layout-for-each-row – M-Wajeeh Apr 15 '13 at 12:53

0 Answers0