在我的android應用程序中,Iam有6個spinners,我需要根據類別wise.and Iam使用json檢索數據併發回到android但在這裏我沒有得到如何分配數據spinners.Please幫我解決這個問題。從android數據庫中加載多個spinners在android中
public void getItems(int l)
{
//Toast.makeText(getApplicationContext(), ""+l, 5000).show();
AsyncHttpClient client = new AsyncHttpClient();
RequestParams autofill_params = new RequestParams();
autofill_params.put("sending_category_id_JSON",autofill_composeJSONfromSQLite(l));
//Toast.makeText(getApplicationContext(), "Sending JSON ==> "+autofill_params,5000).show();
client.post("http://www.XXXX.com/mobile_cycle/spares_auto_fill.php", autofill_params, new AsyncHttpResponseHandler()
{
@Override
public void onSuccess(String response)
{
//Toast.makeText(getApplicationContext(), "Responce is ==>"+response, 5000).show();
//spinner_updater();
Gson gson = new GsonBuilder().create();
try
{
JSONArray arr = new JSONArray(response);
//Toast.makeText(getApplicationContext(), "Length ==> "+arr.length(), 5000).show();
//public String temp_array[];
final String[] temp_array = new String[5];
for (int i = 0; i < arr.length(); i++)
{
JSONObject obj = (JSONObject) arr.get(i);
//auto_first_name = obj.get("name").toString();
//Toast.makeText(getApplicationContext(), "Length ==> "+arr.length(), 5000).show();
String item_name = obj.get("name").toString();
temp_array[i] = item_name;
//spinner_updater(item_name);
}
spinner_updater(temp_array);
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
//fillData(autofill_network_flag);
}
@Override
public void onFailure(int statusCode, Throwable error,String content)
{
if (statusCode == 404)
{
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}
else if (statusCode == 500)
{
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]",
Toast.LENGTH_LONG).show();
}
}
});
}
public void spinner_updater(String[] item_name)
{
Toast.makeText(getApplicationContext(), "Inside Updater Item Length ==> "+item_name.length, 5000).show();
for(int length = 0; length < item_name.length; length++)
{
String empty_temp = " ";
String temp_item = item_name[length];
if(temp_item.equals(empty_temp))
{
//Toast.makeText(getApplicationContext(), "Item ==> "+item_name[length], 5000).show();
}
else
{
Toast.makeText(getApplicationContext(), "Item ==> "+item_name[length], 5000).show();
}
}
ArrayAdapter<String> adp2 = new ArrayAdapter<String>
(this, android.R.layout.simple_dropdown_item_1line, str1);
sp2.setAdapter(adp2);
}
你在哪裏在DB – raj
插入數據根據我的情況,有在我的數據庫5個CATEGORY_ID所以根據他們我應該加載5個紡紗與數據。我已經檢索了數據,但我現在應該將它們存儲在數組中,並將該數組分配給微調適配器。 – Vandana
這個鏈接是從mysql數據庫填充微調器的一個很好的例子。 http://www.androidhive.info/2013/12/android-populating-spinner-data-from-mysql-database/ –