0

私はアンドロイドの連絡先からデータ電話を送信するためのコードを持っています。私たちが知っているように、Androidの電話連絡先の多くのデータ。電話の連絡先からデータを取得し、このようなリストビューとして表示するコードがあります

    Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");

                int row = cursor.getCount();
                friend_item = new MenuItem [row];
                int i=0;
                while(cursor.moveToNext()){
                    nama = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                    phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                    friend_item[i] = new MenuItem(nama,phone);
                    i++;
                }

List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("phone", mPhoneNumber));
                params.add(new BasicNameValuePair("friend", phone));

                // getting JSON string from URL
                JSONObject json = jParser.makeHttpRequest(Constants.url_phone_contact, "POST", params);
                 // Check your log cat for JSON reponse
                Log.d("All Friend: ", json.toString());

                try {                    
                    friend = json.getJSONArray("friend");
                    friend_item = new MenuItem[friend.length()]; 
                     // looping through All Products
                    for (int a = 0; a < friend.length(); a++) {
                    JSONObject c = friend.getJSONObject(i); 

                    //Storing each json item in variable
                    String phone_friend= c.getString(TAG_PHONE);

                    friend_item[i] = new MenuItem(nama, phone_friend);

                     // creating new HashMap
                     HashMap<String, String> map = new HashMap<String, String>();

                     // adding each child node to HashMap key => value
                   map.put("nama", nama);
                   map.put("phone", phone_friend);

                   // adding HashList to ArrayList
                      friendList.add(map);
                   }


              } catch (JSONException e) {

                e.printStackTrace();

              }             

        return null;

        }

params.add(new BasicNameValuePair("friend", phone));

フレンドはデータ配列、[phone_contact]からの配列です。では、Androidのサーバーにデータ配列と文字列「mPhoneNumber」を送信するにはどうすればよいですか?ありがとう

4

1 に答える 1

0

このようにサーバーにデータを送信できます。

for(int i=0;i<unique_id.length;i++)
{
     params.add(new BasicNameValuePair("unique_id[]",unique_id[i]));
}

配列値を取得するために for ループを使用し、データを namevaluepairs に割り当てる必要があります。

于 2012-11-12T04:11:29.683 に答える