views:

41

answers:

2

I have an AutoCompleteTextView with a MatrixCursor as an adapter. The AutoCompleteTextView has a OnItemClickListener as follows:

public class AutoCompleteListClickListner implements OnItemClickListener
{
    private AutoCompleteTextView acView;

    public AutoCompleteListClickListner(AutoCompleteTextView view)
    {
        this.acView = view;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        /* tv is the selected view in the dropdown */
        TextView tv = (TextView) ((LinearLayout) view).getChildAt(0);
        Log.d(AndroidLogTag, "Before:>>>>" + this.acView.getText().toString());
        this.acView.setText(tv.getText().toString());
        Log.d(AndroidLogTag, "After:>>>>" + this.acView.getText().toString());
    }
}

When an item is selected I see following in the log

10-14 00:34:37.893: DEBUG/MyApp(19151): Before:>>>>android.database.MatrixCursor@4643e388
10-14 00:34:37.912: DEBUG/MyApp(19151): After:>>>>Ankit V Jain

If you see the log, the Before log entry, the getText() returns a SpannableStringBuilder object and toString() of it returns some object identifier.

How do I get actual text of the auto-complete view which was there just before clicking drop-down item?

A: 

try casting SpannableStringBuilder to CharSequence

Asahi
A: 

Well, there is always another way (dirty or best) in code.

I added a TextWatcher to the AutoCompleteView and used beforeTextChanged() event to record text content and reuse that in onItemClick() !

Ankit Jain