U
U
urmi tilek uulu2015-05-12 16:07:33
Android
urmi tilek uulu, 2015-05-12 16:07:33

How on clicking on the Button which is inside the ListView call to call?

Something like this
95e68fde9ef544b59341c1f35b424fd7.jps
Here is the XML for the list items.

/>

    <TextView.... Имя />

    <TextView...Номер телефона
        android:id="@+id/phone_number" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/call_button"
        android:id="@+id/call_button"" />

And here, when I click on the green button, I need to take the phone number from the ListView and start the call Intent.
I don't know how I'll get the number when I click on the Button.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
drYOM, 2015-05-12
@urma

You can assign a listener to the button in which we find a textview with a number using the parent view:

new OnClickListener(){
      @Override
      public void onClick(View v) {
          View parent = (View) v.getParent();
          TextView numberTextView = (TextView) parent.findViewById(R.id.phone_number);
          String number = numberTextView .getText().toString(); 
      }
};

A
Alexander, 2015-05-12
@NeiroNx

And how do you determine which of the many buttons you clicked? When generating a list from some array, I would add some identifier to the button pointing to an entry in the array. And then, when processing the click, the system sends a link to the click object (button) and you can get any of its parameters.
For example, through setContentDescription() and getContentDescription()

View txt_layout = row.findViewById(R.id.txt_layout);
                txt_layout.setContentDescription(Integer.toString(position));
                txt_layout.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if(view.getContentDescription() == null)return;
                        curPosition = Integer.parseInt(view.getContentDescription().toString());
                    }
                });

Maybe it's not feng shui, but it works.

T
Tiberal, 2015-05-13
@Tiberal

It is possible to sculpt a tag with a number in getView to the button, and pull it out of the view in onClick. Will avoid a bunch of lisenters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question