Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello m working on Autocompletetextview..i have two array of strings..Brand and company ..
My query is when m searching in Autocompletetextview it is not searching through Only Brand keyword..it is seaching thorgh both company and Brand..
i want to search only through Brand..how to do this???

Here is my code:

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

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

public class MainActivity extends Activity {
	
	
	// Array of strings storing country names
    String[] Brand = new String[]{ "XXXXX", "XXXXX", "XXXXX",
			"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX",
			"XXXXX", "XXXXX" };
    
 // Array of integers points to images stored in /res/drawable-ldpi/
    String[] Company = new String[]{ "XXXXX", "XXXXX",
			"XXXXX", "XXXXX", "XXXXX", "XXXXX",
			"XXXXX", "XXXXX", "XXXXX", "XXXXX" };

    String[] Strength=new String[]
		   {
		   "(10 mg)",
		   "(10 mg)",
		   "(30 mg)",
		   "(10 mg)",
		   "(80 mg)",
		   "(10 mg)",
		   "(40 mg)",
		   "(10 mg)",
		   "(50 mg)",
		   "(10 mg)"
		   };
    
   
   int[] flags = new int[]{
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX,
            R.drawable.XXXXX
        };
     

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        // Each row in the list stores country name, currency and flag
        List<hashmap><string,string>> aList = new ArrayList<hashmap><string,string>>();

        for(int i=0;i<10;i++){
                HashMap<string,> hm = new HashMap<string,string>();
            hm.put("Brand", Brand[i]);
            hm.put("flag", Integer.toString(flags[i]) );
            hm.put("Strength", Strength[i]);
            hm.put("Company",Company[i] );
            aList.add(hm);
        }

        // Keys used in Hashmap
        String[] from = {"flag","Brand","Company","Strength"};

        // Ids of views in listview_layout
        int[] to = { R.id.flag,R.id.Brand,R.id.Company,R.id.Strength};

        // Instantiating an adapter to store each items
        // R.layout.listview_layout defines the layout of each item
        SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.autocomplete_layout, from, to);
        
        // Getting a reference to CustomAutoCompleteTextView of activity_main.xml layout file
        CustomAutoCompleteTextView autoComplete = ( CustomAutoCompleteTextView) findViewById(R.id.autocomplete);
        
        
        /** Defining an itemclick event listener for the autocompletetextview */
        OnItemClickListener itemClickListener = new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView        		/** Each item in the adapter is a HashMap object. 
        		 *  So this statement creates the currently clicked hashmap object
        		 * */
        		HashMap<string,> hm = (HashMap<string,>) arg0.getAdapter().getItem(position);
  
        	}
		};
        
		/** Setting the itemclick event listener */
        autoComplete.setOnItemClickListener(itemClickListener);
                
        /** Setting the adapter to the listView */
        autoComplete.setAdapter(adapter);        
        
    }
  
    

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
Posted
Updated 31-Oct-14 4:58am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900