java - How to get all the elements out of ArrayList<HashMap<String, String>> android -


i have arraylist hashmap holds contacts -names , phone numbers-. check , make sure these items in arraylist hashmap before send sql database saving. of code below works, not have clue of how print contents in arraylist. things have tried have not worked , not know how use log...i rather new this.

import android.app.activity; import android.content.contentresolver; import android.content.intent; import android.database.cursor; import android.net.uri; import android.provider.contactscontract; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.textview; import android.widget.toast;  import java.util.arraylist; import java.util.hashmap;   public class contacts extends actionbaractivity { private static final int pick_contact = 1;  private static arraylist<hashmap<string, string>> getcontacts = new arraylist<hashmap<string, string>>();  private static arraylist<hashmap<string, string>> data1 = new arraylist<hashmap<string, string>>();  private static hashmap<string, string> contacts = new hashmap<string,string>();  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_contacts);  }  public void btnaddcontacts_click(view view) {     intent intent = new intent(intent.action_pick, contactscontract.contacts.content_uri);     startactivityforresult(intent, pick_contact); }  public void btndone_click(view view){     intent = new intent(contacts.this, message.class);     startactivity(i); }    @override public void onactivityresult(int reqcode, int resultcode, intent data) {     super.onactivityresult(reqcode, resultcode, data);      switch (reqcode) {         case (pick_contact):             if (resultcode == activity.result_ok) {                 uri contactdata = data.getdata();                 cursor c = managedquery(contactdata, null, null, null, null);                 if (c.movetofirst()) {                     string id =                             c.getstring(c.getcolumnindexorthrow(contactscontract.contacts._id));                      string hasphone =                             c.getstring(c.getcolumnindex(contactscontract.contacts.has_phone_number));                      if (hasphone.equalsignorecase("1")) {                         cursor phones = getcontentresolver().query(                                 contactscontract.commondatakinds.phone.content_uri, null,                                 contactscontract.commondatakinds.phone.contact_id + " = " + id,                                 null, null);                         phones.movetofirst();                         string phn_no = phones.getstring(phones.getcolumnindex("data1"));                         string name = c.getstring(c.getcolumnindex(contactscontract.commondatakinds.structuredpostal.display_name));                         contacts.put(name, phn_no);                           while (c.movetonext()) {                             string id1 = c.getstring(c.getcolumnindex(contactscontract.contacts.lookup_key));                              string name1 = contacts.get(id1);                             string phone = c.getstring(c.getcolumnindex(contactscontract.commondatakinds.phone.data));                              hashmap<string, string> h = new hashmap<string, string>();                             h.put("name", name1);                             h.put("phone", phone);                             data1.add(h);                         }                            toast.maketext(this, "contact info : " + phn_no + "\n" + name, toast.length_long).show();                      }                 }             }     }  }   } 

the xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin"     tools:context="akh.seniorproj.contacts">   <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="contact"     android:id="@+id/contact1"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_margintop="82dp"     android:clickable="true"     android:onclick="btnaddcontacts_click" />   <button     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="contact"     android:id="@+id/contact2"     android:layout_below="@+id/contact1"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_margintop="40dp"     android:clickable="true"     android:onclick="btnaddcontacts_click" />  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="contact"     android:id="@+id/contact3"     android:layout_below="@+id/contact2"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_margintop="49dp"     android:clickable="true"     android:onclick="btnaddcontacts_click" />  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="contact"     android:id="@+id/contact4"     android:layout_below="@+id/contact3"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_margintop="52dp"     android:clickable="true"     android:onclick="btnaddcontacts_click" />  <button     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="next"     android:id="@+id/next1"     android:layout_alignparentbottom="true"     android:layout_alignparentright="true"     android:layout_alignparentend="true"     android:clickable="true"     android:onclick="btndone_click" />   </relativelayout> 

you can print values in data1 using data1.tostring()


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -