検索アクティビティのコードは次のとおりです
search.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
// Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s,
int start, int count, int after)
{
// Abstract Method of TextWatcher Interface.
}
public void onTextChanged(CharSequence s,
int start, int before, int count)
{
textlength = search.getText().length();
array_sort.clear();
for (int i = 0; i < listview_array.length; i++)
{
if (textlength <= listview_array[i].length())
{
if(search.getText().toString().equalsIgnoreCase(
(String)
listview_array[i].subSequence(0,
textlength)))
{
array_sort.add(listview_array[i]);
}
}}
listContent1.setAdapter(new ArrayAdapter<String>
(Search_Food.this,
android.R.layout.simple_list_item_1, array_sort));
}
});
私の onclicklistener コード
AlertDialog.Builder adb = new AlertDialog.Builder(
Search_Food.this);
adb.setTitle("Food Item");
adb.setMessage("Selected Food is = "
+ listContent1.getItemAtPosition(position));
adb.setPositiveButton("Ok", null);
adb.show();
私のバダプター
public LinkedList<String> search(String string) {
// TODO Auto-generated method stub
LinkedList<String> results = new LinkedList<String>();
Cursor cursor = null;
String search = string;
try{
cursor = this.sqLiteDatabase.query(true, MYDATABASE_TABLE , new String[] { KEY_ID , KEY_FOODNAME , KEY_CALORIES }, KEY_FOODNAME + " = ?" + "COLLATE NOCASE",
new String[] { search }, null, null, null, null);
if(cursor!=null && cursor.getCount()>0 && cursor.moveToFirst()){
int foodName = cursor.getColumnIndex(KEY_FOODNAME );
int keyColories = cursor.getColumnIndex(KEY_CALORIES );
// boolean moveToNext = cursor.moveToNext();
//do{
results.add(
new String(
cursor.getString(foodName) + " " +
cursor.getString(keyColories)
)
);
//}while(moveToNext);
}
}catch(Exception e){
Log.e(APP_NAME, "An error occurred while searching for "+search+": "+e.toString(), e);
}finally{
if(cursor!=null && !cursor.isClosed()){
cursor.close();
}
}
return results;
}
検索したリストビューのデータをクリックすると、getitemposition を 2 に抽出したいのですが、それが私の列です。食品名とカロリー。2 つの値を分離するにはどうすればよいですか。
答えてください。ヘルプ。ありがとうございました