I populate the counter with a generic type of type ArrayList of category cat.
Now I want to get the position of a certain element from it; therefore, I tried the code below, but it always returns S.
if (Singleton.getCategory() != null) { cat item =new cat(); String cat= Singleton.getCategory().toString(); int catid= Singleton.getCategoryid(); item.setName(cat); item.setcatId(catid); int spinnerPosition=selcategaryadapter.getPosition(item);
This is how I fill the counter:
JSONArray jsonarray=JSONFunction.getJSONCategary(); JSONObject json1=null; ArrayList<eexit> listCategory= new ArrayList<eexit>(); try { for(int i=0;i< jsonarray.length();i++) { json1=jsonarray.getJSONObject(i); arrayCategary[i]=json1.getString("Name") cat item=new cat(); item.setName(json1.getString("Name")); item.setcatId(Integer.parseInt(json1.getString("CategoryID"))); listCategory.add(item); } } catch (Exception e) { // TODO: handle exception } ArrayAdapter<eexit> selcategaryadapter = new ArrayAdapter<eexit>(Activity.this,R.layout.spinner_layout, listCategory); selcategaryadapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item ); selCategary.setAdapter(selcategaryadapter); selCategary.setPrompt("Select Category");
source share