I use multiautocomplete textview in my application, the elements that I use with mutltiautocompletetextview are from json, now I want when the user selects more than one value, I need to get the identifier of this element, I can get the identifier of only the first element, ..
My answer
{ "category": [ { "id":"4", "name":"cat1" }, { "id":"7", "name":"aditya"} ] }
JsonParse.java
public class JsonParse { double current_latitude,current_longitude; public JsonParse(){} public JsonParse(double current_latitude,double current_longitude){ this.current_latitude=current_latitude; this.current_longitude=current_longitude; } public List<SuggestGetSet> getParseJsonWCF(String sName) { List<SuggestGetSet> ListData = new ArrayList<SuggestGetSet>(); try { String temp=sName.replace(" ", "%20"); URL js = new URL(""); URLConnection jc = js.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream())); String line = reader.readLine(); JSONObject jsonResponse = new JSONObject(line); JSONArray jsonArray = jsonResponse.getJSONArray("category"); for(int i = 0; i < jsonArray.length(); i++){ JSONObject r = jsonArray.getJSONObject(i); ListData.add(new SuggestGetSet(r.getString("id"),r.getString("name"))); } } catch (Exception e1) {
SuggestGetSet.java
public class SuggestGetSet { String id,name; public SuggestGetSet(String id, String name){ this.setId(id); this.setName(name); } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
SuggetionAdapter.java
public class SuggestionAdapter extends ArrayAdapter<String>{ protected static final String TAG = "SuggestionAdapter"; private List<String> suggestions; public SuggestionAdapter(Activity context, String nameFilter) { super(context, android.R.layout.simple_dropdown_item_1line); suggestions = new ArrayList<String>(); } @Override public int getCount() { return suggestions.size(); } @Override public String getItem(int index) { return suggestions.get(index); } @Override public Filter getFilter() { Filter myFilter = new Filter() { @Override protected FilterResults performFiltering(CharSequence constraint) { FilterResults filterResults = new FilterResults(); JsonParse jp=new JsonParse(); if (constraint != null) { List<SuggestGetSet> new_suggestions =jp.getParseJsonWCF(constraint.toString()); suggestions.clear(); for (int i=0;i<new_suggestions.size();i++) { String name=new_suggestions.get(i).getName(); String id=new_suggestions.get(i).getId(); System.out.println("checis id"+id); if(name.contains(constraint)){ suggestions.add(new_suggestions.get(i).getName()); } }
MainActivity.java
JsonParse jp=new JsonParse(); List<NameValuePair> params = new ArrayList<NameValuePair>(); List<SuggestGetSet> list =jp.getParseJsonWCF(acTextView.getText().toString()); for(int i = 0;i<list.size();i++){ if(list.get(i).getName().equals(acTextView.getText().toString())) params.add(new BasicNameValuePair("parentid",list.get(i).getId())); System.out.println("what goes"+params); catid=list.get(i).getId().toString(); }
json android autocomplete multiautocompletetextview
user4767117 Apr 09 '15 at 4:31 on 2015-04-09 04:31
source share