0
私は表示したいハッシュマップを持っています。ユーザーはeditTextに名前を入力し、検索ボタンをクリックするとハッシュマップを通過し、edittextのテキストと一致するエントリをキーで表示する必要があります。アンドロイドでハッシュマップからデータを表示する方法は?
HashMap<String, Staff> h = new HashMap<String, Staff>();
Staff staff = new Staff("Thomas", "133", "[email protected]");
h.put("Thomsas", staff);
私はメモ帳アプリに適応しようとしてい
package android;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.project.R;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
public class SingleStaff extends ListActivity {
private DBAdapter mDbHelper;
private EditText staffName;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchstaff);
staffName = (EditText) findViewById(R.id.staffname);
mDbHelper = new DBAdapter(this);
mDbHelper.open();
registerForContextMenu(getListView());
Button search = (Button) findViewById(R.id.confirm);
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
String a = staffName.getText().toString();
fillData(a);
}
});
}
private void fillData(String staffName) {
Cursor notesCursor = mDbHelper.fetchSingleStaff(staffName);
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{ DBAdapter.STAFF_NAME, DBAdapter.STAFF_ROOM, DBAdapter.STAFF_EMAIL};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1, R.id.text2, R.id.text3};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.note_row_staff, notesCursor, from, to);
setListAdapter(notes);
}
}
私は、アプリケーションを実行してのEditTextに「トーマス」などで入力されたと私はエラーメッセージを取得し、検索をクリックしたときに、
android.database.sqlite.SQLiteException: no such column: Thomas: , while compiling: SELECT
DISTINCT _id, name, room, email FROM staff WHERE name=Thomas
'fetchSingleStaff'の内容を表示してください。私の賭けは、あなたが 'Thomas'の周りに一重引用符を必要としているということです - 'WHERE name = 'Thomas'' – ccheneson
残念ながら私はこの情報をデータベースから取得しようとしましたが、これはfetchSingleStaffのコードですpublic Cursor fetchSingleStaff(String staffName)throws SQLException { カーソルmCursor = mDb.query(真、STAFF_TABLE、新しいString [] {STAFF_ROWID、 \t \t STAFF_NAME、STAFF_ROOM、STAFF_EMAIL}、STAFF_NAME + "=" + staffName、ヌル、 NULL、NULL、NULL、ヌル); if(mCursor!= null){ mCursor.moveToFirst(); } return mCursor; } – Waz
どのように私は代わりにハッシュマップを使用することができますこのメソッドを適応させることができます – Waz