Android 的listview中使用一个布局文件中的不同textview时,当有的行的textview visiable属性设置为gone时会导致另外的行出现问题,怀疑是重用导致的,不知道有没有好的解决办法?

解决方案 »

  1.   

    就是重用的问题。
    你自己写一个adapter,重写getView,在里面先调用父类的getView,然后对返回的这个View做一些gone或者反向操作。
      

  2.   

    public View getView(int position, View convertView, ViewGroup parent)
    {
    // TODO Auto-generated method stub
    if (convertView == null)
    {
    convertView = mInflater.inflate(R.layout.listview, null);
    }
    if (contents.get(position).getTopic)
    {
    TextView topic = (TextView) convertView.findViewById(R.id.title);
    topic.setText(contents.get(position).getName());

    TextView admin = (TextView) convertView.findViewById(R.id.admin);
    admin.setVisibility(View.GONE);

    }
    else
    {
    TextView admin = (TextView) convertView.findViewById(R.id.admin);
    admin.setText(contents.get(position).getAdmin());
    TextView topic = (TextView) convertView.findViewById(R.id.title);
    topic.setText(contents.get(position).getName());
    } return convertView; }
    基本上是这样写的,找不出原因
      

  3.   

    else
    {
    TextView admin = (TextView) convertView.findViewById(R.id.admin);
    admin.setText(contents.get(position).getAdmin());
    //这里加一句,让控件显示出来,就是和View.GONE相反的,叫什么我忘记了。
    TextView topic = (TextView) convertView.findViewById(R.id.title);
    topic.setText(contents.get(position).getName());
    }
      

  4.   

    admin.setVisibility(View.VISIBLE);谢啦
      

  5.   

    这个listView是重用的,好像会屏幕下边滚上来的一个如果不设置的话默认是采用刚刚滚出的一个布局