android - Why do the selected contacts not appear in the textview? -


i creating multiple choice layout contact list. pick contacts. however, instead of displaying contact name in text view,it appear string value. want contact name appear in textview not string values.

i got 2 classes. 1 class pick contact. while other class browsing , selecting contacts.

selected contact activity

package com.droidnova.android.samples;   import android.app.activity;   import android.content.intent;   import android.database.cursor;   import android.os.bundle;   import android.provider.contacts.people;   import android.provider.contactscontract.contacts;   import android.view.view;   import android.widget.button;      public class selectcontact extends activity {  private static final int pick_contact = 0;  private button btnpick;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.button);          btnpick = (button)findviewbyid(r.id.button);         btnpick.setonclicklistener(new myonclicklistener());       }     @override      protected void onactivityresult(int requestcode, int resultcode, intent data) {         if (requestcode == pick_contact) {             if (resultcode == result_ok) {                 cursor contact = getcontentresolver().query(data.getdata(), null, null, null, null);                 contact.movetofirst();                 string name = contact.getstring(contact.getcolumnindexorthrow(people.name));           }      }        }     private class myonclicklistener implements view.onclicklistener {      @override    public void onclick(view v) {          startactivityforresult(new intent(intent.action_pick),pick_contact);   }   } } 

contacts activity

package com.droidnova.android.samples;   import java.util.arraylist;  import java.util.list;  import java.util.zip.inflater;  import android.app.listactivity;  import android.content.context;  import android.content.intent;  import android.content.dialoginterface.onclicklistener;  import android.database.cursor;  import android.os.bundle;  import android.provider.contacts.people;  import android.util.log;  import android.util.sparsebooleanarray;  import android.view.view;  import android.widget.adapter;  import android.widget.arrayadapter;  import android.widget.edittext;  import android.widget.listadapter;  import android.widget.listview;  import android.widget.simplecursoradapter;  import android.widget.textview;   public class contacts extends listactivity { listview list; textview selection;    private static string[] projection = new string[] {     people._id,     people.name,     people.number, };    @override  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      list=(listview)findviewbyid(android.r.id.list);     cursor cursor = getcontentresolver().query(people.content_uri,              projection, null, null, null);     startmanagingcursor(cursor);      listadapter adapter = new simplecursoradapter(this,android.r.layout.simple_list_item_multiple_choice,             cursor,new string[]{people.name},new int[]{android.r.id.text1});      getlistview().setchoicemode(2);    setlistadapter(adapter);     selection = (textview)findviewbyid(r.id.selection);    }   @override    protected void onlistitemclick(listview parent,view v,int position,long id){   selection.settext("");   sparsebooleanarray chosen = parent.getcheckeditempositions();   for(int i=0;i<chosen.size();i++)   {           log.d("selection", "index:"+i+";key:"+chosen.keyat(i) +";value:"+chosen.valueat(i)                   +";"+projection[chosen.keyat(i)]);            if(chosen.valueat(i)){               selection.append(projection[chosen.keyat(i)]+"");           }        }   } 

}


this logcat:

12-02 03:10:49.840: info/activitymanager(53): starting activity: intent {    act=android.intent.action.main cat=[android.intent.category.launcher] flg=0x10000000 cmp=com.droidnova.android.samples/.selectcontact } 12-02 03:10:49.930: info/activitymanager(53): start proc com.droidnova.android.samples activity com.droidnova.android.samples/.selectcontact: pid=715 uid=10025 gids={1015} 12-02 03:10:49.930: debug/androidruntime(709): shutting down vm 12-02 03:10:49.930: debug/dalvikvm(709): destroyjavavm waiting non-daemon threads exit 12-02 03:10:49.940: debug/dalvikvm(709): destroyjavavm shutting vm down 12-02 03:10:49.940: debug/dalvikvm(709): heapworker thread shutting down 12-02 03:10:49.940: debug/dalvikvm(709): heapworker thread has shut down 12-02 03:10:49.940: debug/jdwp(709): jdwp shutting down net... 12-02 03:10:49.940: info/dalvikvm(709): debugger has detached; object registry had 1 entries 12-02 03:10:49.960: debug/dalvikvm(709): vm cleaning 12-02 03:10:49.990: error/androidruntime(709): error: thread attach failed 12-02 03:10:50.030: debug/dalvikvm(709): linearalloc 0x0 used 639500 of 5242880 (12%) 12-02 03:10:50.230: debug/ddm-heap(715): got feature list request 12-02 03:10:50.910: info/activitymanager(53): displayed activity com.droidnova.android.samples/.selectcontact: 1000 ms (total 1000 ms) 12-02 03:10:51.921: info/activitymanager(53): starting activity: intent { act=android.intent.action.pick cmp=com.droidnova.android.samples/.contacts } 12-02 03:10:52.441: info/activitymanager(53): displayed activity com.droidnova.android.samples/.contacts: 431 ms (total 431 ms) 12-02 03:10:53.521: debug/selection(715): index:0;key:0;value:true;_id 12-02 03:10:54.391: debug/selection(715): index:0;key:0;value:true;_id 12-02 03:10:54.391: debug/selection(715): index:1;key:1;value:true;name 12-02 03:10:54.841: debug/selection(715): index:0;key:0;value:true;_id 12-02 03:10:54.851: debug/selection(715): index:1;key:1;value:true;name 12-02 03:10:54.851: debug/selection(715): index:2;key:2;value:true;number 12-02 03:10:57.531: debug/dalvikvm(220): gc freed 43 objects / 2024 bytes in 77ms 12-02 03:11:24.040: debug/selection(715): index:0;key:0;value:false;_id 12-02 03:11:24.040: debug/selection(715): index:1;key:1;value:true;name 12-02 03:11:24.050: debug/selection(715): index:2;key:2;value:true;number 12-02 03:11:25.120: debug/selection(715): index:0;key:0;value:false;_id 12-02 03:11:25.120: debug/selection(715): index:1;key:1;value:false;name 12-02 03:11:25.130: debug/selection(715): index:2;key:2;value:true;number 12-02 03:11:25.670: debug/selection(715): index:0;key:0;value:false;_id 12-02 03:11:25.680: debug/selection(715): index:1;key:1;value:false;name 12-02 03:11:25.680: debug/selection(715): index:2;key:2;value:false;number 12-02 03:11:26.641: debug/selection(715): index:0;key:0;value:true;_id 12-02 03:11:26.641: debug/selection(715): index:1;key:1;value:false;name 12-02 03:11:26.651: debug/selection(715): index:2;key:2;value:false;number 12-02 03:11:27.171: debug/selection(715): index:0;key:0;value:true;_id 12-02 03:11:27.181: debug/selection(715): index:1;key:1;value:true;name 12-02 03:11:27.181: debug/selection(715): index:2;key:2;value:false;number 12-02 03:49:00.191: debug/dalvikvm(53): gc freed 17933 objects / 880976 bytes in 150ms 12-02 04:22:34.131: debug/dalvikvm(102): gc freed 11675 objects / 524064 bytes in 81ms 12-02 04:38:00.181: debug/dalvikvm(53): gc freed 20167 objects / 943152 bytes in 147ms 

try this..i using code email , name contact. use code per requirement

@override     protected void onactivityresult(int requestcode, int resultcode, intent data)      {                              if (resultcode == result_ok)                      {                        if(requestcode==contact_picker_email)                        {                            cursor cursor = null;                             string email = "";                             try                              {                                 uri result = data.getdata();                                 log.v(debug_tag, "got contact result: "                                         + result.tostring());                                  // contact id uri                                 string id = result.getlastpathsegment();                                  // query email                                 cursor = getcontentresolver().query(email.content_uri,                                         null, email.contact_id + "=?", new string[] { id },                                         null);                                  int emailidx = cursor.getcolumnindex(email.data);                                  // let's first email                                 if (cursor.movetofirst())                                 {                                     email = cursor.getstring(emailidx);                                                                     txtconfirmby.settext(email);                                 }                                  else                                  {                                     log.w(debug_tag, "no results");                                 }                             }                              catch (exception e)                              {                                 log.e(debug_tag, "failed email data", e);                             }                                                           {                                 if (cursor != null)                                  {                                     cursor.close();                                 }                                                    }                              }                        else if (requestcode==contact_picker_name)                         {                            uri contactdata = data.getdata();                             cursor c = managedquery(contactdata, null, null, null, null);                             if (c.movetofirst())                              {                                                        string name = c.getstring(c.getcolumnindexorthrow(people.display_name));                                 txtparticipant.settext(name);                                         }                            }                      }         } 

send request details this

intent intent = new intent(intent.action_pick, contactscontract.contacts.content_uri);             startactivityforresult(intent, contact_picker_email);  intent intent = new intent(intent.action_pick,contactscontract.contacts.content_uri);                        startactivityforresult(intent,contact_picker_name); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -