I recently did this. Suppose I want an invisible button in a listItem element. Then, in the getView of the list adapter, add this button to the global vector. as shown below.
Button del_btn = viewCache.getFrame(); view_vec.add(del_btn);
Here, viewCache is an object of the ViewCache class, which looks like this:
class ViewCache { private View baseView; private Button button; public ViewCache(View baseView) { this.baseView = baseView; } public Button getButton() { if(button == null) { button = (Button) baseView.findViewById(R.id.DeleteChatFrndBtn); } return button; } }
Now you like to see the listItem button when you click on another button. Then the code looks below -
public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.EditChatFrndBtn: length = view_vec.size(); for(int i = 0; i < length; i++) { Button btn = (Button) view_vec.elementAt(i); btn.setVisibility(View.VISIBLE); } doneBtn.setVisibility(View.VISIBLE); editBtn.setVisibility(View.INVISIBLE); break; } }
Instead of R.id.EditChatFrndBtn put your button identifier by clicking on which you will be an invisible / visible listItem button.
Debarati
source share