1. Check out our app, Forums for Android! Download and leave feedback here!

how to get the selected contact number?

Discussion in 'Application Development' started by smego, Feb 9, 2009.

  1. smego

    smego New Member
    Thread Starter
    5

    Jan 11, 2009
    2
    0
    5
    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 (Text):
    1.  
    2. package com.android.IPDial;
    3.  
    4. import android.app.Activity;
    5. import android.app.ListActivity;
    6. import android.content.Intent;
    7. import android.database.Cursor;
    8. import android.net.Uri;
    9. import android.os.Bundle;
    10. import android.provider.Contacts.Phones;
    11. import android.view.Menu;
    12. import android.view.MenuItem;
    13. import android.widget.ListAdapter;
    14. import android.widget.SimpleCursorAdapter;
    15.  
    16.  
    17.  
    18. public class IPDial extends ListActivity/*Activity implements
    19. OnClickListener*/
    20. {
    21. private static final int IPDIAL_17951_ID = Menu.FIRST;
    22. private static final int IPDIAL_12593_ID = Menu.FIRST + 1;
    23. private ListAdapter adapter;
    24. /** Called when the activity is first created. */
    25. @Override
    26. public void onCreate(Bundle savedInstanceState)
    27. {
    28. super.onCreate(savedInstanceState);
    29. // Get a cursor with all phones
    30. Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null,
    31. null);
    32. startManagingCursor(c);
    33.  
    34. // Map Cursor columns to views defined in simple_list_item_2.xml
    35. /*ListAdapter*/ adapter = new SimpleCursorAdapter(this,
    36. android.R.layout.simple_list_item_2, c,
    37. new String[] { Phones.NAME, Phones.NUMBER },
    38. new int[] { android.R.id.text1, android.R.id.text2 });
    39. setListAdapter(adapter);
    40. }
    41.  
    42. //create options menu to dial
    43. @Override
    44. public boolean onCreateOptionsMenu(Menu menu)
    45. {
    46. super.onCreateOptionsMenu(menu);
    47. menu.add(0, IPDIAL_17951_ID, 0, "17951");
    48. menu.add(0, IPDIAL_12593_ID, 0, "12593");
    49. return true;
    50. }
    51.  
    52. @Override
    53. public boolean onOptionsItemSelected( MenuItem item )
    54. {
    55. switch (item.getItemId())
    56. {
    57. case IPDIAL_17951_ID:
    58. {
    59. //long lSelectedItemId = getSelectedItemId();
    60. String str = getString(getSelectedItemPosition());
    61. //Object obj = adapter.getItem(getSelectedItemPosition());
    62. Intent mIntent = new Intent(android.content.Intent.ACTION_CALL,
    63. Uri.parse("tel:17951"+str) );
    64. startActivity(mIntent);
    65. }
    66. break;
    67.  
    68. case IPDIAL_12593_ID:
    69. {
    70. Intent mIntent = new Intent(android.content.Intent.ACTION_CALL,
    71. Uri.parse("tel:1795101010086") );
    72. startActivity(mIntent);
    73. }
    74. break;
    75. default:
    76. {
    77. }
    78. break;
    79. }
    80. return super.onOptionsItemSelected(item);
    81. }
    82. }
     

    Advertisement

  2. AndroidDeveloper

    5

    Mar 9, 2009
    7
    0
    5
    I have 4 screens A,B,C,D
    If i want to navigate from A->B->C->A

    How to implement for navigation LINK OR BUTTON HOME, PREVIOUS, NEXT, LAST
     

Share This Page

Loading...