Coding Villa Forum
FAQs
Advertisements

Android – Populate contacts from listview

Fazal Online 12/9/2011 10:49:00 AM

Hello Friends!

i want to choose the contacts from a list view and populate the chosen contact in another ui then send a generated message to the chosen contact by sms.

The populateField method doesn't works for me.

 

My code:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:background="@color/pink"
   
android:orientation="vertical" >
   
<TextView
       
android:id="@+id/label_sms_nbr"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="@string/label_sms_nbr"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:textColor="@color/Green" />
   
<TextView
       
android:id="@+id/display_sendSms_name_contact"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:textColor="@color/white" />
   
<TextView
       
android:id="@+id/display_sendSms_contact_nbr"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:textColor="@color/black" />
   
<TextView
       
android:id="@+id/label_sms_msg"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="@string/label_sms_msg"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:textColor="@color/white" />
   
<EditText
       
android:id="@+id/input_sms_msg"
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:inputType="textMultiLine" >
       
<requestFocus />
   
</EditText>
   
<Button
       
android:id="@+id/btn_sms_send"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="@string/label_sms_btn_send" />
</LinearLayout>

Java code:

public class SendSMS extends Activity{

 

     private IShoppingListDao shoppingMgr;

     private TextView mContact;

     private TextView mMgr; 

     private Long mRowId;

     private static final String TAG = "SendSMS";   

     @Override

     public void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);

         setContentView(R.layout.send_list_by_sms);

 

         shoppingMgr = new ShoppingListDao(this); 

         shoppingMgr.open();

 

         mContact = (TextView) findViewById(R.id.display_sendSms_name_contact);

 

         mRowId = null;

         Bundle extras = getIntent().getExtras();

         mRowId = (savedInstanceState == null) ? null : (Long) savedInstanceState

                 .getSerializable(ContactsContract.Contacts.DISPLAY_NAME);

 

         Log.d(TAG, "Row-id: "+mRowId); 

 

         if (extras != null) {

             mRowId = extras.getLong(ContactsContract.Contacts.DISPLAY_NAME);

         }

 

         mMsg = (TextView) findViewById(R.id.input_sms_msg);

         mMsg.setText(generateMsg());

         populateFields(); 

     }

      private void populateFields() {

 

         Log.d(TAG,"Entering populateFields"); 

         Log.d(TAG,"Row-id: "+mRowId); 

         if (mRowId != null) {

 

             ContentResolver contentr = getContentResolver();

             String where = ContactsContract.Contacts._ID + " = " + mRowId;

             Log.d(TAG,"String where: "+where);           

             Cursor listItem = contentr.query(

                     ContactsContract.Contacts.CONTENT_URI, 

                     null, 

                     where, 

                     null, null);

 

             startManagingCursor(listItem);          

             mContact.setText(listItem.getString(

                     listItem.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

         }

     }

 

Please solve me how I solve the above problem

 

Thanks in advance

 

 

Share with Friends

Advertisements

Share with Friends

Post reply

 

Enter This Code
Captcha
 

Subscribe

Email me when people reply


Subscribe to the