4

我正在使用一个简单的适配器在列表视图的不同文本字段中显示一组字符串...我希望当我单击该列表视图中的特定内容时,某些文本视图应该是不可见的.. 怎么做...

我的代码是

String[] from = new String[] {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN"};

int[] to = new int[] { R.id.textView_1, R.id.textView_2, R.id.textView_3, R.id.textView_4, R.id.textView_5, R.id.textView_6, R.id.textView_7};


Adapter adapter = new SimpleAdapter(this, Maps, R.layout.search, from, to);
ListView lvSearch = (ListView) findViewById(R.id.listView_SearchResult);
lvSearchResult.setAdapter(adapter);

点击这里

R.id.textView_5, R.id.textView_6, R.id.textView_7

应该是不可见的

4

4 回答 4

6

不确定您到底在寻找什么,但如果您想要做的只是隐藏 TextView,您可以执行以下操作:

TextView txtView = (TextView)findViewById(R.id.textView_6);
txtView.setVisibility(View.GONE)

如果您向我们提供更多信息,我们可以尝试进一步帮助您。

于 2013-01-07T15:47:05.903 回答
5

设置布局中android:visibility="gone"的属性TextViews R.id.textView_5, R.id.textView_6, R.id.textView_7layout.search

对于您的示例,我猜结果应该如下所示:

<TextView android:id="@+id/textView_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        安卓:文本=“隐藏”
        安卓:可见性=“消失”/>
于 2013-01-07T15:45:18.337 回答
4

SimpleAdapter 中有一个方法可以做到这一点。它被称为 ViewBinder。SimpleAdapter adapter = new SimpleAdapter(this, Maps, R.layout.search, from, to);尝试在之后和之前立即包含这行代码setListAdapter(adapter);

SimpleAdapter.ViewBinder binder = new SimpleAdapter.ViewBinder() {
    @Override
    public boolean setViewValue(View view, Object object, String value) {
        System.out.println("view= "+view);
        System.out.println("view.toString()= "+ view.toString());
        System.out.println("view.getId()= "+ view.getId());
        System.out.println("view.getVisibility()= "+ view.getVisibility());
        System.out.println("view.equals((TextView) view.findViewById(R.id. textView_5))= "+ view.equals((TextView) view.findViewById(R.id.textView_5)));
        if (view.equals((TextView) view.findViewById(R.id.textView_5))) {
            TextView textView_five = (TextView) view.findViewById(R.id. textView_5);
            //Change color/answer/etc for textView_5
        }

        //OR
        if (view instanceof TextView) {
            //Do stuff
            return true;
        }

        return false;
    }
};

adapter.setViewBinder(binder);

setListAdapter(adapter);    

将为您在中setViewValue()的每个R.id.textView_1, R.id.textView_2, R.id.textView_3, R.id.textView_4, R.id.textView_5,调用该方法。该方法将在每个视图/每次绘制上述 s 之一时调用。R.id.textView_6R.id.textView_7adaptersetViewValue()R.id

于 2013-06-15T14:18:06.233 回答
0

覆盖@getView 方法并实现它的自定义视图

  @override
  public View getView (int position, View convertView, ViewGroup parent){
   if( convertView == null ){
    //initialize
    convertView = inflater.inflate(R.layout.list_items, parent, false);
   }
   //Here you can hide or visible 
   return convertView;
   }
于 2018-08-03T07:32:37.743 回答