AutiCompleteTextView

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

AutiCompleteTextView

Postby afser » Wed Jun 24, 2009 11:07 am

Hi Guys,

I am a beginner to Android. I am looking for a program wherein I have a AutocompletetextView window for the addressbook. When i type 'a' in the above said window it should list all the names beginning with a in the address book and i should be able to select it.

Now I got a sample program(MyCaller) from this forum which displays the contacts from the addressbook. I need to use a autocompletetextview option as explained above.

Plese provide me with the code.

Please reply ASAP.

Thanking you all in advance.

Regards
Afser
afser
Freshman
Freshman
 
Posts: 5
Joined: Tue Jun 23, 2009 7:08 pm

Top

Postby pjq » Fri Jun 26, 2009 7:29 am

I think you should look through the API Demos in the SDK,you can find the autocomplete Sample here.



Here is just a Sample I used:
I use the database to store the list used for the autocompletetext adapter
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         arrayList = new ArrayList<String>();
  3.  
  4.         Cursor cursor = QWeather.dbAdapter.getAllItem();
  5.  
  6.         int index = cursor.getColumnIndex(DBAdapter.CITY);
  7.  
  8.         String city;
  9.  
  10.         if (cursor.moveToFirst()) {
  11.  
  12.             do {
  13.  
  14.                 city = cursor.getString(index);
  15.  
  16.                 arrayList.add(city);
  17.  
  18.                 Log.i("SearchDialog", city);
  19.  
  20.  
  21.  
  22.             } while (cursor.moveToNext());
  23.  
  24.         }
  25.  
  26.  
  27.  
  28.         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  29.  
  30.                 android.R.layout.simple_dropdown_item_1line, arrayList);
  31.  
  32.         inputCity = (AutoCompleteTextView)findViewById(R.id.searchDialogInput);
  33.  
  34.         inputCity.setAdapter(adapter);
  35.  
  36.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4





A Sample in the API Demos:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3. package com.example.android.apis.view;
  4.  
  5.  
  6.  
  7. import com.example.android.apis.R;
  8.  
  9.  
  10.  
  11. import android.app.Activity;
  12.  
  13. import android.widget.Spinner;
  14.  
  15. import android.widget.ArrayAdapter;
  16.  
  17. import android.widget.AutoCompleteTextView;
  18.  
  19. import android.os.Bundle;
  20.  
  21. import android.view.View;
  22.  
  23.  
  24.  
  25.  
  26.  
  27. public class AutoComplete1 extends Activity {
  28.  
  29.  
  30.  
  31.     @Override
  32.  
  33.     protected void onCreate(Bundle savedInstanceState) {
  34.  
  35.         super.onCreate(savedInstanceState);
  36.  
  37.         setContentView(R.layout.autocomplete_1);
  38.  
  39.  
  40.  
  41.         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  42.  
  43.                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
  44.  
  45.         AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit);
  46.  
  47.         textView.setAdapter(adapter);
  48.  
  49.     }
  50.  
  51.  
  52.  
  53.     static final String[] COUNTRIES = new String[] {
  54.  
  55.         "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
  56.  
  57.         "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
  58.  
  59.         "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
  60.  
  61.         "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
  62.  
  63.         "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
  64.  
  65.         "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory",
  66.  
  67.         "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
  68.  
  69.         "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  70.  
  71.         "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
  72.  
  73.         "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
  74.  
  75.         "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
  76.  
  77.         "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  78.  
  79.         "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
  80.  
  81.         "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
  82.  
  83.         "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
  84.  
  85.         "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
  86.  
  87.         "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
  88.  
  89.         "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
  90.  
  91.         "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
  92.  
  93.         "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
  94.  
  95.         "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
  96.  
  97.         "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
  98.  
  99.         "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
  100.  
  101.         "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
  102.  
  103.         "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
  104.  
  105.         "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
  106.  
  107.         "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
  108.  
  109.         "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
  110.  
  111.         "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
  112.  
  113.         "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
  114.  
  115.         "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
  116.  
  117.         "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
  118.  
  119.         "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
  120.  
  121.         "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
  122.  
  123.         "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
  124.  
  125.         "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
  126.  
  127.         "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
  128.  
  129.         "Ukraine", "United Arab Emirates", "United Kingdom",
  130.  
  131.         "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
  132.  
  133.         "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
  134.  
  135.         "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
  136.  
  137.     };
  138.  
  139. }
  140.  
  141.  
  142.  
  143.  
Parsed in 0.063 seconds, using GeSHi 1.0.8.4
pjq
Freshman
Freshman
 
Posts: 7
Joined: Fri May 15, 2009 1:36 am

Postby afser » Sat Jun 27, 2009 3:30 pm

Thanks pjq!!!!!!

Got a sample from APIdemo and a lil bit of modification and got it working.

Thanks again. :-)
afser
Freshman
Freshman
 
Posts: 5
Joined: Tue Jun 23, 2009 7:08 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests