我正在使用一个简单的适配器在列表视图中的不同文本字段中显示字符串集...我想当我点击该列表视图中的特定内容时,某些textview应该是不可见的.. 怎么做......
我的代码是
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
应该是不可见的
答案 0 :(得分:5)
不确定您在这里寻找的是什么,但如果您想要做的只是隐藏TextView,您可以执行以下操作:
TextView txtView = (TextView)findViewById(R.id.textView_6);
txtView.setVisibility(View.GONE)
如果您向我们提供更多信息,我们可以尝试进一步帮助您。
答案 1 :(得分:4)
为布局android:visibility="gone"
TextViews R.id.textView_5, R.id.textView_6, R.id.textView_7
设置属性layout.search
对于您的示例,我猜结果应如下所示:
<TextView android:id="@+id/textView_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hidden" android:visibility="gone"/>
答案 2 :(得分:2)
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
调用R.id.textView_6
方法,R.id.textView_7
,adapter
。每次查看时都会调用setViewValue()
方法/每次正在绘制上述R.id
之一。
答案 3 :(得分: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;
}