0
私はJSONレスポンスから "client_id"と "organization"のリストを取得しました。これらの組織リストをスピナーに送る必要がありますが、その後、サーバーにその組織に関連付けられているのclient_idを渡す必要があります。ここに スピナーの値を選択し、その値をアンドロイドのサーバに渡します
が私のコードである。try {
//*** Getting Array of Attributes
attributes = jsonreturn.getJSONObject(TAG_ATTRIBUTE);
String status = attributes.getString(TAG_VALIDCODE);
JSONObject clients = jsonreturn.getJSONObject(TAG_CLIENTS);
JSONArray client = clients.getJSONArray(TAG_CLIENT);
final String[] list_client_id = new String[client.length()+1];
list_client_id[0]= "Select Client";
final String[] list_client_name = new String[client.length()];
if(status.equals("200")){
for(int i = 0; i < client.length(); i++)
{
JSONObject clientlist = client.getJSONObject(i);
//***** Storing each JSON item in variable
String client_id = clientlist.getString(TAG_CLIENT_ID);
String organization = clientlist.getString(TAG_ORGANIZATION);
list_client_id[i+1]= clientlist.getString(TAG_CLIENT_ID);
list_client_name[i]= clientlist.getString(TAG_ORGANIZATION);
}
}
else{
Toast.makeText(this, "Invalid Details", 1000).show(); }
ClientNameSpinner = (Spinner)findViewById(R.id.ClientId);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, list_client_name);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ClientNameSpinner.setAdapter(adapter);
/* ArrayAdapter<String> adapterid = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, list_client_id);
adapterid.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ClientNameSpinner.setAdapter(adapterid);*/
}
catch (JSONException e)
{
e.printStackTrace();
}
の代わりにのみ、カスタムの両方を一緒に含まれているListArrayオブジェクトlist_client_idとlist_client_name用の二つの異なる文字列配列を使用してあなたのスピナーにそれを渡してください。クリックスピナー項目では、関連するクライアントIDが表示されます。 – user370305
@ user370305私はカスタムオブジェクトListArrayについて考えていません..あなたが知っている場合は、いくつかのリソースを提案してください。 –
http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapterrとhttp://www.softwarepassion.com/android-series-customをご覧ください-listview-items-and-adaptapters /およびhttp://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/ – user370305