Robin Royal
Robin Royal

Reputation: 1850

Android Get Id of Value in AutoCompleteTextView

I'm using xml array with value and its Id.I want to get Id of value after user selects it.Kindly tell me how can I get that?

<string-array name="medicine">
    <item id="21058">ALPHA LIPOIC ACID</item>
    <item id="19699">B 50 VITAMIN</item>
    <item id="19470">B100 ULTRA  50S</item>
</string-array>

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_item, getResources().getStringArray(R.array.medicine));
    AutoCompleteTextView actv= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
    actv.setOnClickListener(this);
    actv.setThreshold(1);
    actv.setAdapter(adapter);

Upvotes: 1

Views: 2240

Answers (1)

Robin Royal
Robin Royal

Reputation: 1850

I have found its answer myself. I made a model for ArrayList, I assign that ArrayList to the AutoCompleteTextView Adapter and then, the OnClick event of the AutoCompleteTextView gives me the exact id and value.

Upvotes: 3

Related Questions