0

こんにちは、データベースからリスト ビューにコンテンツを表示するための簡単なアプリケーションを作成しましたが、リスト ビューにデータが表示されません。私は初心者であり、支援が必要です。

以下のリストビュークラスを与える

public class Show extends Activity {

    //SQLiteDatabase db;
    //Datahelper dh;
    Context context=this;
    Dataclass dc;

    private ListView mainListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);

        mainListView=(ListView)findViewById(R.id.list);

        //getDetails();
        dc=new Dataclass(this);
        Bundle bundle=getIntent().getExtras();
        String message=bundle.getString("MSG");
        List<String> friendlist=dc.getDetails(message);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_activated_1,friendlist);

        mainListView.setAdapter(adapter);
    }

    public void onDestroy() {
        super.onDestroy();
        dc.close();
    }
}

bundle を使用して 1 つのアクティビティからこのアクティビティにデータを渡し、データを取得しましたが、データベースからデータが取得されません。

以下のデータクラスからgetdetails関数を与える

public List<String> getDetails(String message) {
    List<String> Friendlist = new ArrayList<String>(); 

    String selectQuery="SELECT * FROM Mytables WHERE Name='" + message + "' ";
    db = dh.getWritableDatabase();

    Cursor cursor = db.rawQuery(selectQuery, null);
    cursor.moveToFirst();
    while(cursor.moveToNext()) {
        Friendlist.add(cursor.getString(1));
    }
    return Friendlist;
}

以下のリストアクティビティのxmlレイアウトを与える

           <?xml version="1.0" encoding="utf-8"?>
         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" 
             >

          <ListView
          android:id="@+id/listview"
           android:layout_width="match_parent"
            android:layout_height="wrap_content" >
          </ListView>

          </LinearLayout>
4

2 に答える 2