Reputation: 77
I have three autoCompleteTextView
box as home
, work
, other
.
So in home autocomplete box i get a data from server and select one item and that item i stored to home_latlong
string. Similarly i have to get value from other autocomplete work which i am storing that value in another string called home_latlong
. Below code shows onItemClick
overridden function where i will store home_latlong
or work_latlong
.
`
ontemClick(AdapterView<?> adapterView, View view,
int position, long id) {
System.out.println("POSITION ="+position);
for (int i = 0; i < latlong.size(); i++) {
if(i==position){
home_latlong=latlong.get(i);
System.out.println("ARRAY"+latlong.get(i));
}
}
}`
So problem is i am not able differenciate when i will store home_latlong
and when to store work_latlong
. I tried with id of autocompletetextview
but it did not help in this function.
Upvotes: 1
Views: 1100
Reputation: 77
I solved it by using anonymous inner class ,
actv1 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
actv1 .setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View v, int position,
long id) {
// TODO Auto-generated method stub
for (int i = 0; i < latlong.size(); i++) {
if (i == position) {
home_latlong = latlong.get(i);
System.out.println("ARRAY" + latlong.get(i));
}
}
}
});
Similarly for work_latlong
i had another anonymous inner class so i can get which autocompleteview i have clicked.
Upvotes: 1
Reputation: 55350
Check the documentation for AdapterView.OnItemClickListener
:
public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)
Parameters
- parent: The AdapterView where the click happened.
- view: The view within the AdapterView that was clicked (this will be a view provided by the adapter)
You need to use the first parameter (the AdapterView) to identify the AutocompleteTextView
.
Upvotes: 0