0

我试图隐藏一个列表视图,一旦我单击一个项目,然后在其中显示一个按钮,但在 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();
                                }

                            });

非常感谢。

4

1 回答 1

2

那是因为lv超出了onItemClick(AdapterView<?> adapter, View view, int position, long arg).

但是,AdapterView<?>参数实际上是对包含列表视图的引用,因此您可以简单地更改

lv.setVisibility(View.GONE);

adapter.setVisibility(View.GONE);
于 2013-05-31T11:04:30.707 回答