0

I have the below code:

   ArrayList NumList = getIntent().getParcelableArrayListExtra ("number");

   ArrayList MailList = getIntent().getParcelableArrayListExtra ("email");

    // This array list will be updated each time.

    mAdapter = new MyCustomAdapter();
    mAdapter.addItem(Name);

    if (!NumList.isEmpty()) {
        mAdapter.addSeparatorItem("Phone");
        mAdapter.addAll(NumList);
    }

    if (!MailList.isEmpty()) {
        mAdapter.addSeparatorItem("Email");
        mAdapter.addAll(MailList);
    }

    setListAdapter(mAdapter);
}

I want to be able to click on the list of numbers and call the selected number.

fasheikh
  • 419
  • 3
  • 19

2 Answers2

0

This post will probably help you: How to handle ListView click in Android

You have to instantiate an OnClickListener and register it with your ListView. Use setOnItemClickListener of the ListView class for this.

Community
  • 1
  • 1
rocky3000
  • 1,134
  • 8
  • 9
0

I am guessing you are using a ListActivity or ListFragment, so implement your calling logic in onListItemClick or place an onClickListener on each of the views when you create them in your custom adapter like so:

view.setOnClickListener (new OnClickListener() {
  public boolean onClick( View view) {
    //do your stuff here
  }
});

The logic for making a call looks like this:

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:0123456789"));
startActivity(callIntent);

Edit:

And remember add this CALL_PHONE permission to your Manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />
Qw4z1
  • 3,041
  • 1
  • 24
  • 36
  • I am using ListActivity but I can't seem to implement the listener, where exactly does it need to go? – fasheikh Aug 23 '12 at 12:16
  • onListItemClick is a protected method in ListActivity that you simply override. Method signature looks like: protected void onListItemClick(ListView l, View v, int position, long id). setOnClickListener is used on the view that you return from getView() in MyCustomAdapter – Qw4z1 Aug 23 '12 at 12:19
  • sorry I must be really dense, but what goes in the brackets of convertView.setOnClickListener(); – fasheikh Aug 23 '12 at 12:33
  • new OnClickListener(){ public boolean onClick(View v){ //your magic code } } – Qw4z1 Aug 23 '12 at 12:34
  • i'm getting the error: Cannot instantiate the type View.OnClickListener – fasheikh Aug 23 '12 at 12:36
  • See this question for an example http://stackoverflow.com/questions/3505841/onclick-listener-in-android – Qw4z1 Aug 23 '12 at 12:38