I have to parse data from server to spinner. Now I want to delete some value from Spinner .
Here is my code .
mytaxList include all values. Now I want put check that if TaxType is compound delete TaxName and TaxValue of that type from spinner. Actually i donot want to display cound type tax in spinner. i.e i want to remove compound type tax from ArrayList mytaxList.
JSONObject taxes = returnTaxlist.getJSONObject(TAG_TAXES);
Object tax ;
if (taxes.optJSONArray("tax") != null){
//The result isn't null so it is a JSONArray
tax = taxes.optJSONArray("tax");
}
else
{
//The result is null so it isn't a JSONArray
tax = taxes.optJSONObject("tax");
}
if (tax instanceof JSONObject){
// The object is a JSONObject
tax = taxes.getJSONObject(TAG_TAX);
}
else
{
// The object is a JSONArray
tax = taxes.getJSONArray(TAG_TAX);
mytaxList = new ArrayList<TaxList>();
for(int i = 0; i <=((JSONArray)tax).length(); i++)
{
if(i==0){
TaxList iTaxClass = new TaxList();
iTaxClass.setTaxId("");
iTaxClass.setTaxName("--Select--");
iTaxClass.setTaxType("");
iTaxClass.setTaxvalue("");
mytaxList.add(iTaxClass);
continue;
}
JSONObject taxlist = ((JSONArray)tax).getJSONObject(i-1);
TaxList iTaxClass = new TaxList();
//***** Storing each JSON item in variable
iTaxClass.setTaxId(taxlist.getString(TAG_TAX_ID));
iTaxClass.setTaxName(taxlist.getString(TAG_TAX_NAME));
iTaxClass.setTaxType(taxlist.getString(TAG_TAX_TYPE));
iTaxClass.setTaxvalue(taxlist.getString(TAG_TAX_VALUE));
mytaxList.add(iTaxClass);
}
tax1 = (Spinner)findViewById(R.id.item1);
tax1.setAdapter(new TaxListAdapter(mytaxList,this));
tax1.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View selectedItemView, int position, long id)
{
TaxListAdapter taxlistvalue = (TaxListAdapter)parent.getAdapter();
taxlistvalue.getItemId(position);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
Before adding into
ArrayListcheck this condition forCustomtax object, if it has add object into arraylist else no need to add.