我想基于tagid反映所有冰箱项目,但大小为 ArrayList
返回null,ArrayIndexOutOFBoundException
。我已使用selectCategory
微调器反映子类别名称列表,同时我也希望使用所选类别的tagid
来反映在微调器中选择的类别项目Gridview
。我有这样的JSON数据。如何在Spinner中使用两个数组列表,根据标记ID在网格视图中反映数据
JSON结果:
{
"code": "200",
"action": "success",
"message": "Your request has successfully completed",
"status": "1",
"subcategory_detail": [
{
"category_id": "113626",
"category": "Refrigerators",
"tag_id": "818415",
"type_id": "63942",
"disp_order": "0",
"shop_id": "7508"
},
{
"category_id": "113627",
"category": "Air Condition",
"tag_id": "818416",
"type_id": "63942",
"disp_order": "1",
"shop_id": "7508"
},
{
"category_id": "113628",
"category": "Kitchen Appliances",
"tag_id": "818417",
"type_id": "63942",
"disp_order": "2",
"shop_id": "7508"
},
{
"category_id": "113629",
"category": "Utilities",
"tag_id": "818418",
"type_id": "63942",
"disp_order": "3",
"shop_id": "7508"
},
{
"category_id": "113634",
"category": "Washing Machine",
"tag_id": "818434",
"type_id": "63942",
"disp_order": "4",
"shop_id": "7508"
}
]
}
OnItemSelectedListener:
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
str = selectCategory.getSelectedItem().toString();
subcatIdList=new ArrayList<>();
subcattagidList = new ArrayList<>();
Log.d("categoryidid",""+subcatIdList.size());
int x=selectCategory.getSelectedItemPosition();
String y=subcatIdList.get(position+1);
Toast.makeText(getApplicationContext(),"List ID "+y,Toast.LENGTH_SHORT).show();
if (position == 0)
{
getSupportActionBar().setTitle("" + category_name);
}else {
getSupportActionBar().setTitle("" + str);
b = str;
Toast.makeText(ProductListGridView.this,"b:"+b,Toast.LENGTH_SHORT).show();
// new AsyncSearchingTask().execute();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
的AsyncTask类:
class SubCatList extends AsyncTask<String, String, JSONObject> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(String... args) {
UserFunction userFunction = new UserFunction();
JSONObject json = userFunction.getSubCAtList(category_id);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
try {
if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
JSONArray posts = json.getJSONArray("subcategory_detail");
for (int i = 0; i < posts.length(); i++) {
JSONObject post = posts.getJSONObject(i);
a=post.getString("category_id").toString();
b=post.getString("category").toString();
c = post.getString("type_id").toString();
Log.e("Response categorywise", "" + b);
Log.e("Response categoryidwise",""+a);
Log.e("Response categorytagid",""+c);
subcatIdList.add(a);
subcatNameList.add(b);
subcattagidList.add(c);
}
}else if(Integer.parseInt(res) == 0){
// Toast.makeText(getApplicationContext(), "Something went wrong!", Toast.LENGTH_LONG).show();
}
}
Log.d("monacategoryid",""+subcatIdList.size());
Log.d("monaTagid",""+subcatIdList.size());
Toast.makeText(getApplicationContext(), "c"+c, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
你可以发布你的代码,你想要做什么以及你如何做,以及你面临的问题是什么。你的问题不清楚.. –
我想使用c值在微调框中显示gridview中的项目基于存储在c中的tagid。如果在微调器中使用,则返回零tagid数组大小。 –
y的值是抛出数组零的大小和IndexoutofBoundexception,Plz的帮助。 –