【发布时间】:2012-08-27 06:39:58
【问题描述】:
我已在布局中将按钮设置为不可见,现在我需要将其设置为在长按列表项时可见..
我创建了一个扩展数组适配器的类,我在这个类中声明了按钮..
现在我需要在代码中访问此按钮以长按列表项以将其设置为可见..
我如何在setOnItemLongClickListener.. 中访问此按钮。
当在 arrayadapter 中声明按钮时,应用程序强制关闭。
这是我的代码..
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//arg1.findViewById(R.id.btndelete).setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), "long press", Toast.LENGTH_LONG).show();
return false;
}
});
class myAdapter extends ArrayAdapter<String>
{
Button btndlt;
View row;
public myAdapter(Context context,ArrayList<String> objects)
{
super(context, android.R.layout.simple_list_item_1, objects);
}
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater=getLayoutInflater();
row = inflater.inflate(R.layout.list_item, parent, false);
btndlt = (Button) row.findViewById(R.id.btndelete);
}
}
【问题讨论】:
-
尝试在适配器类中设置视图的
onitemlongclickListener。并且,使那里的可见性。我不确定,这是否正确。 -
我想你得到了答案here
-
@Abhi:不,我没有得到答案..
标签: android android-arrayadapter long-press