我正在尝试使 Button 更改我所有 Listview 元素中单个 ImageButton 的可见性。我遇到的问题是找到要访问的正确元素,因为我没有简单的方法来访问自定义适配器中的特定元素(我认为)
相关代码部分:
public View getView(final int position, final View convertView, final ViewGroup parent) {
View vi=convertView;
if(convertView==null)
{
vi = inflater.inflate(R.layout.custom_row_view, null);
}
/*
other non important view stuff
*/
if(deleteButton != null){
deleteButton.setVisibility(View.INVISIBLE);
deleteButton.setTag(position);
deleteButton.setOnClickListener(deleteListener);
}
return vi;
}
public void setVisibility()
{
if(deleteButton.getVisibility() == View.INVISIBLE){
deleteButton.setVisibility(View.VISIBLE); //Here i want to access all elements
Log.i("setVisibility", "Changing to "+ deleteButton.getVisibility() + " element: " + deleteButton.getTag());
//Logcat output: Changing to 0 element: 2
} else if(deleteButton.getVisibility() == View.VISIBLE){
deleteButton.setVisibility(View.INVISIBLE);
Log.i("setVisibility", "Changing to "+ deleteButton.getVisibility() + " element: " + deleteButton.getTag());
//Logcat output: Changing to 4 element: 2
}
}
我在主要活动中使用的东西:
CustomAdapter listAdapter;
ListView listViewLeft;
ListView listViewRight;
OnCreate:
listAdapter=new CustomAdapter(this, link, names, names2, buttonText,context, plistArray);
listViewLeft.setAdapter(listAdapter);
listViewRight.setAdapter(listAdapter);
我只需使用以下方法调用该方法:
OnClickListener editListener = new OnClickListener() {
public void onClick(View view) {
listAdapter.setVisibility();
}
}
如果有人有任何想法,我会非常感激,谢谢:)