How to differentiate buttons from a Listview?

Asked

Viewed 35 times

0

I have a ListView with ImageButtons in each row, and I want when I click the button it saves the product with the price, so I add in an Activity. How do I get the line information from the button clicked?

Uma tela com uma lista de linhas, onde cada linha tem um produto com um preço diferente e o mesmo ícone de carrinho de compras na frente

  • But what is the doubt?

  • how can I count these Buttons, since it creates the button as a string is added

  • But what has to do with counting the buttons to save the product with the price?

  • if I click the button, it will save the product and the price, how do I do it, sorry if I’m not able to express myself

  • All right. I edited your question by removing the information not related to doubt. Remember to only say what is relevant so your question doesn’t get too big. Also, when someone asks for clarification in the comments, remember that you can (and should!) edit your question with the details instead of just putting them in the comments. Another tip: put descriptions on the images, otherwise your question becomes invisible to screen reader users. Take a look at how I did it if you want an idea of how it’s done. Otherwise, welcome!

1 answer

3


You can associate a slightly different Switch for each of these buttons directly in the Adapter. Your getView would look something like this:

public View getView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = getLayoutInflater();
    View linha = inflater.inflate(R.layout.linha_de_produto, parent,
                        false);
    ImageButton carrinhoButton = (ImageButton)  linha.findViewById(R.id.carrinhoButton);
    carrinhoButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
               // Aqui entra o código que vai usar a variável position para fazer uma coisa diferente pra cada caso.
        }

    });
}
  • 1

    Yeah, that’s what I wanted. I’m sorry I got caught up in the question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.