Home Ask Login Register

Developers Planet

Your answer is one click away!

Deve February 2016

More than one contentDescription for a button

In my activity I have a method that reads the contentDescription of a button and get the phone number and calls it.

I have a list of all departments in the company. But if for the same department we have more than one number what should I do. How to add more than one contentDescription for a button to pop a dialog that allows the user to choose between which number should he call.

public class ContactUs extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

    ImageView back = (ImageView) findViewById(R.id.back);
    back.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(ContactUs.this , Introduction.class);
            overridePendingTransition(R.animator.slide_in, R.animator.slide_out);


public void onClickCall(View view) {

    final String phoneNumber = view.getContentDescription().toString().trim();

    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            switch (which){
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://" + phoneNumber));

                case DialogInterface.BUTTON_NEGATIVE:
                    //No button clicked
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Test Alert").setPositiveButton("Yes", dialogClickListener)
            .setNegativeButton("No", dialogClickListener).show();




Null n Void February 2016

When your are setting content description to button append them with commas separated.

after appending all the phone numbers your content description will be like //phoneNumber1,phoneNumber2,phoneNumber3

now read content description from your view

final String allPhoneNumbers = view.getContentDescription().toString().trim();

//say phoneNumber1,phoneNumber2,phoneNumber3

String[] arrPhoneNumbers = allPhoneNumbers .split(",");

now you have all phone numbers in this array.

Post Status

Asked in February 2016
Viewed 2,406 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life