0

ListView で sqlite データベースのデータ項目を表示する際に問題があります。ボタンをクリックした後にデータを見ようとすると、次のように表示されます。

com.LocationReminder と Task@4053afb0

それは奇妙だ。

これは私のreadReminder.javaです

import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class readReminder extends ListActivity {
private DBReminder operasiDB;
private ArrayList<Task> daftarTugas;

 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.read_task);
     operasiDB = new DBReminder(this);

     daftarTugas = operasiDB.viewAllTask();
     ArrayAdapter<Task> adapter = new ArrayAdapter<Task>(this,
         android.R.layout.simple_list_item_1, daftarTugas);

     setListAdapter(adapter);
 }
}

これは、データベースからすべてのデータを表示するための私のコードです

public ArrayList<Task> viewAllTask() {
    openConn();
    ArrayList<Task> tugas = new ArrayList<Task>();
    Cursor curs = db.rawQuery("select * from " + TableName, null);
    if (curs.moveToFirst()) {
        do {
            Task task = new Task();
            task.setId(Integer.parseInt(curs.getString(curs.getColumnIndex(ID))));
    task.setLatitude(Integer.parseInt(curs.getString(curs.getColumnIndex(LATITUDE))));               
task.setLongitude(Integer.parseInt(curs.getString(curs.getColumnIndex(LONGITUDE)));
task.setRadius(Integer.parseInt(curs.getString(curs.getColumnIndex(RADIUS))));
task.setAlamat(curs.getString(curs.getColumnIndex(ALAMAT)));
task.setKonteks(curs.getString(curs.getColumnIndex(KONTEKS_TUGAS)));
tugas.add(task);
        } while (curs.moveToNext());
    }
    closeConn();
    return tugas;
}

SQLite Manager Eclipse では、データはテーブルと共に表示されます。私を助けてください。ありがとうございました...

4

3 に答える 3

0

クラスAdapterを拡張して独自のものを作成する必要があります。ArrayAdapter

于 2013-03-27T04:54:11.860 に答える
0

リストビューに複数の列を表示する場合は、SimpleCursorAdapter を使用します

public Cursor viewAllTask() {
//openConn(); open your database in the activity onCreate

return db.rawQuery("select * from " + TableName, null);

//closeConn(); // close your database in the activity onDestroy
} 

private ArrayList<Task> daftarTugas; に変更Cursor daftarTugas;

 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.read_task);
 operasiDB = new DBReminder(this);
 operasiDB.open();

 Cursor daftarTugas = operasiDB.viewAllTask();
 String[] fromColumns = {DBReminder.RADIUS, 
                         DBReminder.ALAMAT,
                         DBReminder.KEY_KONTEKS_TUGAS};
int[] toViews = {R.id.textview_radius, 
                 R.id.textview_alamat,
                 R.id.textview_konteks_tugas};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
                            R.layout.listview_items,
                            daftarTugas, fromColumns, toViews, 0);
        setListAdapter(adapter);
 }  

レイアウト XML 名 listview_items

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/textview_radius"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView 
    android:id="@+id/textview_alamat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView 
    android:id="@+id/textview_konteks_tugas"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>
于 2013-03-27T04:55:44.753 に答える
0

デフォルトでは、ArrayAdaptor クラスは、提供されたリソース ID が単一の TextView を参照することを想定しています。これをカスタマイズする必要があります。

simplecursoradoptor を使用するシンプルで簡単な方法。

于 2013-03-27T06:46:33.487 に答える