Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:19:25+00:00 2026-05-27T12:19:25+00:00

I try to create a AutoCompleteTextView with custom list items, like showing a picture

  • 0

I try to create a AutoCompleteTextView with custom list items, like showing a picture and a name in one list item. I know how to create it with 1 line of text in a list item but i’m a bit confused on who to do this with more views. I was thing about a ListAdapter and assigning the values to the right views. I’m pretty stuck here. I hope someone can give me a push in the right direction. Question is updated below.

Main activity:

public class AutocompleteCustomActivity extends Activity {

String[] firstView = {"Apple","Banana","Strawberry"};
String[] secondView = {"Green","Yellow","Red"};

AutoCompleteTextView autocomplete;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /*
    // Simple 1 line list item
    this.autocomplete = (AutoCompleteTextView) findViewById(R.id.autocomplete);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, firstView);
    autocomplete.setAdapter(adapter);
    */

    // 2 Lines of text in list item
    this.autocomplete = (AutoCompleteTextView) findViewById(R.id.autocomplete);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.two_list_items, firstView);
    autocomplete.setAdapter(adapter);

}
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

 </LinearLayout>

UPDATE:

After a lot of hardcore Googling and trial and erroring i came up with this code. I think it’s pretty oké but the list items keep showing after selecting one. I know it’s the settext that opens the new listitems.

I found this post: Disable Android AutoCompleteTextView after user selects item from drop down

But i don’t know what he means 🙁 Anyone knows how to fix this?

package com.sb.autocompletecustom;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.SimpleAdapter;

public class AutocompleteCustomActivity extends Activity {

AutoCompleteTextView autocomplete;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Data to fill autocomplete
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();

    Map<String, String> curGroupMap = new HashMap<String, String>();
    list.add(curGroupMap);
    curGroupMap.put("name", "Banana");
    curGroupMap.put("color", "Yellow");

    curGroupMap = new HashMap<String, String>();
    list.add(curGroupMap);
    curGroupMap.put("name", "Strawberry");
    curGroupMap.put("color", "Red");

    curGroupMap = new HashMap<String, String>();
    list.add(curGroupMap);
    curGroupMap.put("name", "Strawberry");
    curGroupMap.put("color", "Black");


    // 2 Lines of text in list item
    this.autocomplete = (AutoCompleteTextView) findViewById(R.id.autocomplete);

    SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.two_list_items, new String[] { "name", "color" }, new int[] { R.id.textView1, R.id.textView2 });
    autocomplete.setAdapter(adapter);

    autocomplete.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> p, View v, int pos, long id) {
            Map<String, String> map = (Map<String, String>) p.getItemAtPosition(pos);
            String itemName = map.get("name");
            autocomplete.setText(itemName);
        }
    });


}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:19:26+00:00Added an answer on May 27, 2026 at 12:19 pm

    use a custom list adapter. you can inflate the layout and assign the values

    public class AutoCompleteCursorAdapter extends CursorAdapter implements Filterable{
        private TextView  txtDrName, txtDrugName, txtDrugManufacturer;
        private int rowResID;
        private static Cursor c;
        private String autoCompleteTextName;
        Context context;
    
    int layout;
    public AutoCompleteCursorAdapter(Context context, int layout ) {
        super(context, c);
        //    this.c = c;
        this.context = context;
        this.autoCompleteTextName = autoCompleteTextName;
        this.layout = layout;
    
    }
    public long getItemId(int position) {  
        return position;
    }
    
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
    
        final LayoutInflater inflater = LayoutInflater.from(context);
    
        View v = inflater.inflate(layout, parent, false);
    
    
            txtDrName = (TextView)v.findViewById(R.id.txtAutoName) ;
            ....
    
    
    
    }
    
            return v;
    
    
    
        }
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
    
    
            txtDrName = (TextView) view.findViewById(R.id.txtAutoName) ;
    
    }
    
    @Override
    public String convertToString(Cursor cursor) {
        // this method dictates what is shown when the user clicks each entry in your autocomplete list
        String name="";
    
            name = cursor.getString(cursor.getColumnIndex("prefix"))+" "+cursor.getString(cursor.getColumnIndex("firstName"));
    
    
        }
    
    
        return name;
    }
    
    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        // this is how you query for suggestions
        if (getFilterQueryProvider() != null) 
        { return getFilterQueryProvider().runQuery(constraint); }
        if(constraint!=null){
    
            DataBaseHelper db = new DataBaseHelper(context);
            db.openDataBase();
            if(autoCompleteTextName.equals(AppConstants.AUTOCOMPLETEDOCTORNAME)){
                c = db.getStaffStartingWith((String) constraint);
    
            }
            else if (autoCompleteTextName.equals(AppConstants.AUTOCOMPLETEDRUGNAME)){
                c = db.getDrugsForStartingWith((String) constraint);
            }
    
            c.moveToFirst();
            db.close();
        }
        return c;
    }
    

    `

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try create custom format for maven assembly plugin. I use following instruction how
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,
I try to create a very simple app using windows API. I've done some
I try to create 2 buttons inside my app case WM_CREATE:{ hWnd =CreateWindowEx(NULL, LBUTTON,
i try to create an AEP for my advantage Database. I create a AEP
I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
I try to create a form that can save a person's form data so
I try to create some li elements in my XUL Application. Theres only the
When I try to create a SQL Server Login by saying CREATE LOGIN [ourdomain\SQLAccessGroup]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.