I am getting data from JSON in below format
{
"success": 1,
"message": "done",
"data": [
{
"name": "Central Construction",
"id": 11
},
{
"name": "IT",
"id": 12
},
{
"name": "Marketing",
"id": 13
},
{
"name": "Sales",
"id": 14
}
]
}
In my Response i am getting the object from data and storing it in my Model
JSONObject parentObject = new JSONObject(response);
JSONArray parentArray = parentObject.getJSONArray("data");
staffData = gson.fromJson(parentArray.toString(),StaffResponseModel.StaffData[].class);
staffName = new ArrayList<String>();
for(StaffResponseModel.StaffData staff : staffData) {
staffName.add(staff.getName());
staffName.add(String.valueOf(staff.getId()));
}
setUpAutoComplete();
And finally in my SetupAutoComplete
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item,staffName);
visitingStaffTextView.setAdapter(adapter);
visitingStaffTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int index, long l) {
String staff = adapter.getItem(index).toString();
Toast.makeText(visitorSignInActivity.this,staff,Toast.LENGTH_LONG).show();
}
});
In the Toast i can see the name which selected and also sets it in the EditText, however i am currently unable to save the id of selected name, as i need to use/post that to server. I have seen quite a few question on stackoverflow and also tried to implement them but had no luck.
I am showing the name on AutoCompeleteEditText.. I need to store the id value in a variable to post to server.
Any Suggestion how i can get the id when name is selected?