K
K
Konstantin Kanaev2015-05-07 09:33:26
Android
Konstantin Kanaev, 2015-05-07 09:33:26

How to implement button onclick in listview android?

Hello. There was a little difficulty with the custom listview. In each line of the list there is a button that should become invisible when it is clicked. For some reason, when I click on any button, the last one is hidden.
Here is the getView method code from my adapter

@Override public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
      view = LayoutInflater.from(context).inflate(R.layout.list_menu, parent, false);
      holder.btn1 = (Button)view.findViewById(R.id.button1);
      holder.btn1.setOnClickListener(this);
      view.setTag(holder);
      } else {
        holder = (ViewHolder) view.getTag();
      }
    Model item = (Model)getItem(position);
    ---------------------------------------		
    return view; 
  }

As you understand, I process the click through the implementation of the onClickListener interface.
@Override
  public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button1:
      holder.btn1.setVisibility(View.INVISIBLE);
      break;
    default:
      break;
    }
    
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-05-07
@Yoh_Asakura

public void onClick(View v)
Why are you passing the View in the ?
v.setVisibility(View.INVISIBLE);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question