私はアンドロイドアプリケーションに取り組んでいます。私のアプリケーションには、2 つの編集テキスト フィールドを持つアクティビティが含まれています。最初の編集テキスト フィールドには、ユーザーが入力したタイトルが格納され、次の編集テキスト フィールドには、ユーザーが入力したばかりのタイトルに関してユーザーが入力したストーリーまたはデータが格納されます。エントリはデータベース テーブルに保存されています。
入力されたエントリを見つけることができる検索ボックスを作成しようとしていました。検索ボックス http://android-helper.blogspot.in/2011/03/android-search-in-listview-example.htmlの次のページを読みました が、ここでは最初に保存するすべてのリスト項目を取得しました文字列配列で。
データベースからタイトル フィールドを取得したいのですが、ユーザーが検索ボックスに特定の単語を入力すると、その特定の単語が入力されたタイトルのみが表示されます。
これは、私の主な活動、つまり日記活動のコードの一部です。
public class DiaryActivity extends Activity implements OnClickListener,
OnItemClickListener {
public static final String ROW_ID = "row_id";
static long row_passed;
ImageButton add;
ListView list;
public static int position_item;
static long id_item_clicked;
SimpleCursorAdapter myAdapter;
DataHolder myDataHolder; // <-- database class
EditText Text;
static String title = "";
static String story = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialiseVariables();
registerForContextMenu(list);
add.setOnClickListener(this);
}
@SuppressWarnings("deprecation")
private void initialiseVariables() {
// TODO Auto-generated method stub
add = (ImageButton) findViewById(R.id.addButton);
list = (ListView) findViewById(R.id.mylist);
try {
myDataHolder = new DataHolder(DiaryActivity.this);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
myDataHolder.open();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Error");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
} finally {
Cursor c = myDataHolder.getAll();
c.moveToFirst();
// Log.d("Message", c.getString(1));
myAdapter = new SimpleCursorAdapter(DiaryActivity.this,
R.layout.mystoryholder, c, new String[] {
// get the date from the system
DataHolder.KEY_TITLE, DataHolder.KEY_DAY,
DataHolder.KEY_MONTH, DataHolder.KEY_YEAR },
new int[] { R.id.titleTag, R.id.tvDate, R.id.tvMonth,
R.id.tvYear });
list.setAdapter(myAdapter);
list.setOnItemClickListener(this);
myDataHolder.close();
}
}
データベースから title_fields のすべてのエントリを取得し、それらを個々の文字列に変換して文字列配列に配置するにはどうすればよいですか?さらなるコーディングに使用されます。