As the following code, I don't know how to get the contact number from ListActivity after that number is selected. Can you guy tell me which API or something I can use?
Code:
package com.android.IPDial;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.Phones;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
public class IPDial extends ListActivity/*Activity implements
OnClickListener*/
{
private static final int IPDIAL_17951_ID = Menu.FIRST;
private static final int IPDIAL_12593_ID = Menu.FIRST + 1;
private ListAdapter adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Get a cursor with all phones
Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null,
null);
startManagingCursor(c);
// Map Cursor columns to views defined in simple_list_item_2.xml
/*ListAdapter*/ adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, c,
new String[] { Phones.NAME, Phones.NUMBER },
new int[] { android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);
}
//create options menu to dial
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0, IPDIAL_17951_ID, 0, "17951");
menu.add(0, IPDIAL_12593_ID, 0, "12593");
return true;
}
@Override
public boolean onOptionsItemSelected( MenuItem item )
{
switch (item.getItemId())
{
case IPDIAL_17951_ID:
{
//long lSelectedItemId = getSelectedItemId();
String str = getString(getSelectedItemPosition());
//Object obj = adapter.getItem(getSelectedItemPosition());
Intent mIntent = new Intent(android.content.Intent.ACTION_CALL,
Uri.parse("tel:17951"+str) );
startActivity(mIntent);
}
break;
case IPDIAL_12593_ID:
{
Intent mIntent = new Intent(android.content.Intent.ACTION_CALL,
Uri.parse("tel:1795101010086") );
startActivity(mIntent);
}
break;
default:
{
}
break;
}
return super.onOptionsItemSelected(item);
}
}