0

私のAndroidアプリでは、通常のリストビューをいくつか使用していますが、 SQLiteデータベースString []からのリストビューを1つ持っています。それは問題ではありません。問題は、ログに記録されているように見え、トーストを使用して文字列を表示するときに、どのオプションを押したかをログに記録することですandroid.database.sqlite.sqlitecursor@????

オプション名でやりたいことをするためにコーディングする必要があります

したがって、誰かがオプション名を文字列に保存してトーストで使用するのを手伝ってくれると本当に助かります...それが私がコードをテストする方法だからです。ありがとう

それが役立つ場合は、以下のリストビューを満たすコードを投稿します

FavouritesScreen.java... リストビューで SQLite 値を使用する

final ListView list = (ListView) findViewById(R.id.listView1);
@SuppressWarnings("deprecation")
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, //context
    android.R.layout.simple_list_item_1, db.getValues(), //Cursor
    new String[] {"SocietyName"}, new int[] {
        android.R.id.text1
    });
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
  public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    String favname = (String)((Cursor) list).getString(position);
    Toast.makeText(getApplicationContext(), favname, Toast.LENGTH_SHORT).show();
  }
});

MyDBAdapter.java... SQLite データベースから値を取得しています

public Cursor getValues() {
  if (!isOpen()) {
    open();
  }
  System.out.println("3a");
  Cursor mCursor = db.query(true, "Favourites", // table name
  new String[] {
    "_id", "SocietyName"
  }, // select clause
  null, // where clause
  null, // where clause parameters
  null, // group by
  null, // having
  null, // order by
  null); // limit
  System.out.println("4a");
  return mCursor;
}
4

2 に答える 2

1

listCursor ではなく ListView です (例外がスローされると予想していました)。

String favname = (String) ((Cursor) list).getString(position);

getString()最初に Cursor を取得してから、関心のある列を 呼び出します。

String favname = ((Cursor) list.getItemAtPosition(position)).getString(columnIndex);
/* I assume the column you want is 1 */
于 2013-04-17T16:10:19.643 に答える
0

android.database.sqlite.sqlitecursor@????」

String favname = (String) ((Cursor) list).getString(position);

デフです。文字列ではなく、SQLLite カーソルを提供します。代わりにカーソル オブジェクトを使用して、必要な文字列を取得します。

おそらく、リストに関連付けられている Adapter オブジェクトを取得してから、カーソルを要求し、その位置にあるものを要求する必要があります。

または、さらに良いことに、この男を使用してください:

public void onItemClick(AdapterView<?> arg0

AdapterView オブジェクト。その「arg0」オブジェクトに、その位置で必要なものを尋ねます。

Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(position), Toast.LENGTH_SHORT).show();
于 2013-04-17T16:11:01.293 に答える