我正在尝试隐藏列表视图,一旦我点击某个项目,然后在其中显示一个按钮,但在setOnItemClickListener内部,列表视图是不可访问的。我该怎么办?
// Binding resources Array to ListAdapter
lv.setAdapter(new ArrayAdapter<String>(
MainActivity.this, R.layout.list_venues,
listItems));
// Click event for single list row
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter,
View view, int position, long arg) {
// TODO Auto-generated method stub
Button here = (Button) findViewById(R.id.iamhere);
lv.setVisibility(View.GONE);
here.setVisibility(View.VISIBLE);
Toast.makeText(
getApplicationContext(),
"Osea que andamos por "
+ listItems.get(position),
Toast.LENGTH_LONG).show();
}
});
非常感谢。
答案 0 :(得分:2)
这是因为lv
超出onItemClick(AdapterView<?> adapter, View view, int position, long arg)
的范围。
但是,AdapterView<?>
参数实际上是对包含listview的引用,因此您只需更改
lv.setVisibility(View.GONE);
到
adapter.setVisibility(View.GONE);