I am trying to make a Button change the visibility of a single ImageButton in all of my Listview Elements. The problem i’m having is finding the right element to access, because i don’t have an easy way to access a specific element in the Custom Adapter (i think)
Relevant code parts:
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
}
}
Stuff i use in the Main Activity:
CustomAdapter listAdapter;
ListView listViewLeft;
ListView listViewRight;
OnCreate:
listAdapter=new CustomAdapter(this, link, names, names2, buttonText,context, plistArray);
listViewLeft.setAdapter(listAdapter);
listViewRight.setAdapter(listAdapter);
I call on the method simply using:
OnClickListener editListener = new OnClickListener() {
public void onClick(View view) {
listAdapter.setVisibility();
}
}
If anyone has any ideas then i’d really appreciate it, Thanks 🙂
It was a really simple fix. I forgot calling:
But every time you call that method, the getView method is called, so i just added this in the custom adapter getView
And set the default in XML to visible.
I’m not sure if this is the most efficient way to do it, but it works like intended at least 🙂