I’m looking a refer for a implement about listview and autocompletetextview....i dont find it...can anyone help me with my code above…thanks Igor
public class Restaurants extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.restaurants);
ListRestaurants();
ListAutoCompleteRestaurants();
} catch (Exception e) {
// TODO: handle exception
Log.e("oncreate resta",e.getMessage());
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
String[] FROM = {"_id","res_name", "res_city"};
Intent its = new Intent(getBaseContext(),RestaurantsDetails.class);
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
try {
dbAdapter.createDataBase();
} catch (IOException e) {
// TODO: handle exception
Log.e("*** select ",e.getMessage());
}
dbAdapter.openDataBase();
Cursor c = dbAdapter.selectRecordsFromDB("restaurants", FROM,null,null,null,null,null);
c.moveToPosition(position);
Bundle b = new Bundle();
b.putLong("key",id);
its.putExtras(b);
startActivity(its);
}
public void ListAutoCompleteRestaurants(){
String[] FROM = {"_id","res_name", "res_city"};
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
try {
dbAdapter.createDataBase();
} catch (IOException e) {
// TODO: handle exception
Log.e("*** select ",e.getMessage());
}
dbAdapter.openDataBase();
Cursor c = dbAdapter.selectRecordsFromDB("restaurants", FROM,null,null,null,null,null);
ArrayList<String> restaurants_names = new ArrayList<String>();
for(c.moveToFirst(); c.moveToNext(); c.isAfterLast())
{
String mTitleRaw = c.getString(c.getColumnIndex("res_name"));
restaurants_names.add(mTitleRaw);
}
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteButecos);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.restaurant_row_2, restaurants_names);
textView.setAdapter(adapter);
dbAdapter.close();
}
public void ListRestaurants(){
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
String[] FROM = {"_id","res_name", "res_city"};
int NumberRows = 0;
int[] TO = {R.id._id,R.id.res_name,R.id.res_city};
try {
dbAdapter.createDataBase();
} catch (IOException e) {
// TODO: handle exception
Log.e("*** select ",e.getMessage());
}
dbAdapter.openDataBase();
Cursor c = dbAdapter.selectRecordsFromDB("restaurants", FROM,null,null,null,null,null);
NumberRows = c.getCount();
TextView txtEmpty = (TextView)findViewById(R.id.txtEmpty);
if (NumberRows != 0) {
txtEmpty.setVisibility(0);
}else {
txtEmpty.setVisibility(1);
}
SimpleCursorAdapter sAdapter = new SimpleCursorAdapter(this,R.layout.restaurant_row,c,FROM,TO);
setListAdapter(sAdapter);
dbAdapter.close();
}
}