在列表视图中向下滚动状态下的切换按钮将变为先前关闭状态

时间:2013-03-02 07:19:44

标签: android listview togglebutton

这是我的myadapterclass的getview方法

public View getView(int position,View convertView,ViewGroup parent)     {         pos = position;

    ApplicationInfo entry = ai.get(position);
    String str = insatllApps.get(position);
    System.out.println("Position============"+(insatllApps.get(position)));
    //Log.d("Check>>:","size>>"+insatllApps.size());
    convertView = mInflater.inflate(R.layout.list__button, null);
    t1=(TextView)convertView.findViewById(R.id.textView1);
    iv=(ImageView)convertView.findViewById(R.id.imageView1);
    tb1=(ToggleButton)convertView.findViewById(R.id.togal);
    tb1.setOnClickListener(this);
    tb1.setTag(pos);
    tb1.setTag(R.id.togal, str);

    iv.setImageDrawable(entry.loadIcon(mPackManager));


    t1.setText(str);


            return convertView;
}

1 个答案:

答案 0 :(得分:-1)

这是有效的解决方案

     View row=null
    ApplicationInfo entry = ai.get(position);
        String str = insatllApps.get(position);
        System.out.println("Position============"+(insatllApps.get(position)));
        //Log.d("Check>>:","size>>"+insatllApps.size());
        row= mInflater.inflate(R.layout.list__button, null);
        t1=(TextView)row.findViewById(R.id.textView1);
        iv=(ImageView)row.findViewById(R.id.imageView1);
        tb1=(ToggleButton)row.findViewById(R.id.togal);
        tb1.setOnClickListener(this);
        tb1.setTag(pos);
        tb1.setTag(R.id.togal, str);

        iv.setImageDrawable(entry.loadIcon(mPackManager));


        t1.setText(str);

return row 

在getView方法中创建一个新视图