Я делаю приложение, которое может искать в таблице «сотрудник» и возвращать результаты.Как я могу использовать адаптер массива для этого?Я новичок в Android.
public class SimpleSearch extends Activity {
/** Called when the activity is first created. */
protected SQLiteDatabase db;
Intent intent = getIntent();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
public List<String> doMySearch(String query) {
List<String> result = new ArrayList<String>();
Cursor c = db.query(
"employee",
new String[] { "_id" }, // The column you want as a result of the Query
"firstName like '%?%' OR lastName like '%?%' OR officePhone like '%?%'", // The where-Clause of the statement with placeholders (?)
new String[] { query, query, query }, // One String for every Placeholder-? in the where-Clause
);
while (c.moveToNext()) {
result.add(c.getString(0));
}
c.close();
return result;
}
}