Skip to content Skip to sidebar Skip to footer

Error In Making Call On Button Click Inside Listview

I have a listview with number and an image buton with each number. I want to make call on button click to the number in the row. my getview method is @Override public View getView(

Solution 1:

you should declare the string number in get view method not outside it. change

number=currentStock.getNumber();

to

final String number=currentStock.getNumber();

and delete the string(ie,number) from outside getview method


Solution 2:

You can't findout the problem that way. You have to debug your getView method.

Do that by

1) double click on the first line of the method on the left of the outer frame to see a small point thay represents a breakpoint.

2) Right click on the project and click Debug as Android application.

3) Using the button F6 (in Eclipse) start moving steps untill you find the specific line you code produce error.

4) Now when you know the line it's easier to find out what happened.


Solution 3:

attach the number to the view with setTag, then retrieve it in the click listener. you also don't need a new listener every time, define that once outside the function...

sv.btncall.setTag(number);

then in the onclick listener...

new View.OnClickListener() {
@Override
  public void onClick(View v) {

   String number = (String) v.getTag();
   String phoneCallUri = "tel:"+number;
   Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
   phoneCallIntent.setData(Uri.parse(phoneCallUri));
   activity.startActivity(phoneCallIntent);
  }
}

Post a Comment for "Error In Making Call On Button Click Inside Listview"