0

我正在使用带有扩展 BaseAdapter 的适配器的列表视图。列表视图中的每一行都有多个视图,我希望如果变量的值为“是”,则该行的图片可见,如果值为“否”,则消失。

但我没有成功。

更改可见性时强制关闭

这是我的代码,非常感谢任何帮助。

谢谢并恭祝安康

public class Adapter_c extends BaseAdapter {
...
public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        View vi=convertView;

        if(convertView==null)
            vi = inflater.inflate(R.layout.row_concursos, null);
        holder = new ViewHolder();
        holder.title = (TextView)vi.findViewById(R.id.title_c);
        holder.image = (ImageView)vi.findViewById(R.id.image_c);
        holder.button = (Button)vi.findViewById(R.id.button_c);



        HashMap<String, String> items = new HashMap<String, String>();
        items = data.get(position);

        try { 
            String imageV = new String(items.get(FIRST_activity.KEY_STATE).getBytes("ISO-8859-1"));
            if (imageV.equals("active")){

                holder.image.setVisibility(View.VISIBLE);
            } else{

                holder.image.setVisibility(View.GONE);
            }

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();}
...
4

3 回答 3

0

尝试在没有 ViewHolder 的情况下获得结果。

(ImageView)vi.findViewById(R.id.image_c).setVisibility(View.GONE);
于 2013-08-14T09:44:21.947 回答
0

更改这组代码:

if(convertView==null)
        vi = inflater.inflate(R.layout.row_concursos, null);
    holder = new ViewHolder();
    holder.title = (TextView)vi.findViewById(R.id.title_c);
    holder.image = (ImageView)vi.findViewById(R.id.image_c);
    holder.button = (Button)vi.findViewById(R.id.button_c);

像这样 :

if(convertView==null)
{
    vi = inflater.inflate(R.layout.row_concursos, null);
    holder = new ViewHolder();
    holder.title = (TextView)vi.findViewById(R.id.title_c);
    holder.image = (ImageView)vi.findViewById(R.id.image_c);
    holder.button = (Button)vi.findViewById(R.id.button_c);        

    vi .setTag(holder);
}
else
    holder = (ViewHolder) vi.getTag();
于 2013-08-14T09:46:51.303 回答
0

试试这个

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;


    if(convertView==null)
    {
    convertView= inflater.inflate(R.layout.row_concursos, parent,false);
    holder = new ViewHolder();
    holder.title = (TextView)convertView.findViewById(R.id.title_c);
    holder.image = (ImageView)convertView.findViewById(R.id.image_c);
    holder.button = (Button)convertView.findViewById(R.id.button_c);
    convertView.setTag(holder);
    }
    else{
     holder=(ViewHolder)convertView.getTag();
     }
     ....some code....
       try { 
          String imageV = new String(items.get(FIRST_activity.KEY_STATE).getBytes("ISO-8859-1"));
          if(imageV.equals("active")){

             holder.image.setVisibility(View.VISIBLE);
           } else{

              holder.image.setVisibility(View.GONE);
           }

         } catch (UnsupportedEncodingException e) {
           e.printStackTrace();
          }
      return converView;
    }
于 2013-08-14T10:04:38.750 回答