0

我用 listfragment 和自定义适配器构建了一个列表!我想要第 25 行填充不同的视图!我的代码在第一次显示视图时工作,当向上滚动列表并排出屏幕时,得到 FC !而如果我评论这一行==> if(row == null){ 代码运行良好,没有问题,但是列表中有很多项目并且列表很慢,因为列表没有优化

    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;


    }
4

0 回答 0