[SOLVED] I need a small help here. I have an ArrayAdapter which contains 2 strings, I want to show user 1st part of the ArrayAdapter and when the users clicks on a particular item i want to get the ID of that specific item and post it. In the below image as you can see i wamt to show JAVA to user and want to send JAVAs ID when users click on button.
Code:
private class getSkillsList extends AsyncTask<String, Void, Void> {
private String dataFetchedFromURL = "";
@Override
protected Void doInBackground(String... skillListURL) {
try {
String newUrl = skillListURL[0];
URL url = new URL(newUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
while (line != null) {
line = bufferedReader.readLine();
dataFetchedFromURL = dataFetchedFromURL + line;
}
System.out.print("DATA: " + dataFetchedFromURL);
JSONArray root = new JSONArray(dataFetchedFromURL);
skillList = new ArrayList<String>();
for (int i = 0; i < root.length(); i++) {
JSONObject jsonObjectHoldingCountries = root.getJSONObject(i);
HashMap<String, Integer> skillsMap = new HashMap<>();
skillsMap.put(jsonObjectHoldingCountries.optString("lookupValue"), jsonObjectHoldingCountries.getInt("lookupValueId"));
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
ArrayAdapter<String> adapter;
for(int i=0; i<skillsMap.size();i++){
skillList.add(String.valueOf(skillsMap.get(i)));
}
adapter = new ArrayAdapter<String>(Skills.this, android.R.layout.simple_list_item_1, skillList);
acSkillTextView.setAdapter(adapter);
}
}
1 UPDATE:
Now i have updated my code and storing the JSON response in HashMap with first key is String and Value is Integer. And when i tried to add those Hashmap in adapter in post execute method it shows NULL in autocompletetext dropdown.
2 UPDATE:
I got my solution, I first inserted all my received data into a HashMap and then from hashmap i inserted key value into an array and displayed that array in dropdown using adapter. Cheers! Thanks guys :)