当我点击listview中的项目时,从sqlite数据库中获取所有相关数据

时间:2017-06-12 08:14:12

标签: android sqlite listview onitemclicklistener

我想访问我的sqlite数据库中与点击onItenclicklistener的项目相关的特定数据。有什么办法吗? 我正在使用基础适配器listview。我正在尝试从最近2天开始,但直到现在还没有完成。任何帮助都将是适合的。

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


            PagesSqliteData pagesSqlite = new PagesSqliteData();
            List<PagesSqliteData>pagesSqliteDataArrayList = new ArrayList<PagesSqliteData>();
            pagesSqlite.setToc_name(bookingsSqliteDataArrayList.get(position).getToc_name());
            pagesSqlite.setContent(compositionSqliteDataArrayList.get(position).getContent());
            pagesSqlite.setCompletion(bookingsSqliteDataArrayList.get(position).getCompletion());
            pagesSqlite.setPageNo(compositionSqliteDataArrayList.get(position).getPage_no());
            pagesSqlite.setCategory_id(bookingsSqliteDataArrayList.get(position).getCategory_id());
            pagesSqlite.setBooking_id(bookingsSqliteDataArrayList.get(position).getBooking_id());
            pagesSqlite.setTable_of_content_id(bookingsSqliteDataArrayList.get(position).getTable_of_content_id());
            pagesSqliteDataArrayList.add(pagesSqlite);

            Intent i = new Intent(MyBookings.this, Pages.class);
            i.putExtra("LIST", (Serializable) pagesSqliteDataArrayList);
            startActivity(i);

    }

数据库表:

 String CREATE_MYBOOKINGS_TABLE = "CREATE TABLE " + MYBOOKINGS + "("+bookingid + " TEXT," +categoryid + " TEXT," +completion + " TEXT," +compositionid+ " TEXT," + contributorid + " TEXT,"+ languageid + " TEXT," +booking_created+ " TEXT,"+ tocname + " TEXT,"+tocid+ " TEXT,"+categoryname+ " TEXT," +cdnId + " TEXT,"+secretToken + " TEXT,"+booking_uploaded + " TEXT,"+ booking_modified + " TEXT"+")";
        db.execSQL(CREATE_MYBOOKINGS_TABLE);


 String CREATE_COMPOSITIONS_TABLE = "CREATE TABLE " + COMPOSITIONS + "("+bookingid_c + " TEXT," +compositionId + " TEXT," +compositionContent +" TEXT," +compositionImage + " TEXT," + compositionCreated + " TEXT,"+ wordCount+ " TEXT,"+ compositionPageno + " TEXT"+")";
        db.execSQL(CREATE_COMPOSITIONS_TABLE);

1 个答案:

答案 0 :(得分:0)

您必须在PagesSqliteData类中实现Serializable。

public class PagesSqliteData implements Serializable 

并在您的活动中使用此代码:

array= (ArrayList<PagesSqliteData >) getIntent().getSerializableExtra("LIST");