私は、テーブル 'employee'を検索して結果を返すアプリケーションを作っています。これを行うにはどうすればアレイアダプターを使用できますか?私はアンドロイドが初めてです。arrayadapterの使い方は?
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;
}
}
代わりにSimpleCursorAdapterを使用する必要があります。 http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/とhttp://groups.google.com/group/android-developers/browse_thread/thread/347c5df5a13fec58?pliを確認してください。 = 1 – Hiral