我正在嘗試使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();
}
}
如果任何人有任何想法,那麼我真的很感激,謝謝:)