2

在我的场景中,我在 sqlite 中有 3 条记录,这些记录是从包含 id、名称、描述和图像的 websercive 中获取的,现在我想在翻转第一条记录后显示第一条记录和第二条记录。在第二条记录翻转后显示 3 条记录。

到目前为止我所做的是

  while (cursor.moveToNext())
    {

         String temp_bookid = cursor.getString(0);
         Log.i("temp_bookid",temp_bookid);
         String temp_desc=cursor.getString(1);
         byte[] temp_image1 = cursor.getBlob(2);
         byte[] temp_image2 = cursor.getBlob(3);
         String temp_id=cursor.getString(4);
         String temp_name = cursor.getString(5);
         String temp_bname=cursor.getString(6);
         mapId.add(temp_id);
         mapBname.add(temp_bname);
         mapBookId.add(temp_bookid);
         mapName.add(temp_name);
         mapDesc.add(temp_desc);
         map2.add(temp_image2);
         map1.add(temp_image1);
            Log.i("temp_id of the page in sqlite", temp_id);

            TextView txtDesc = (TextView) findViewById(R.id.tDescription);
            text = (TextView) findViewById(R.id.tTitle);
            text.setText(temp_name);

            txtDesc.setText(temp_desc);

            ImageView img = (ImageView)findViewById(R.id.smallImage);


            img.setImageBitmap(BitmapFactory.decodeByteArray(temp_image1, 0,temp_image1.length));
            txtName1 = (TextView) findViewById(R.id.tvName);
            txtName1.setText(temp_bname);

            break;
    }   

            mContext = this;
        vf = (ViewFlipper) this.findViewById(R.id.vfShow);
        vf.setOnTouchListener(new OnTouchListener() {
        @Override
            public boolean onTouch(final View view, final MotionEvent event) {
                detector.onTouchEvent(event);
                Log.i("ew","ae");

                return true;
            }
        });

当我设置休息时,我能够显示第一条记录数据;声明,否则它正在显示最后记录数据..如何继续这种方法?

4

1 回答 1

1

List<YourDataClass> myList首先从 onCreate 方法获取所有记录并存储在对象中。正如我刚刚给你的例子

现在,在获取数据并存储在列表对象中之后,您需要实现翻转器更改事件,以便当翻转器更改时获取当前位置并使用此位置从列表对象中获取数据作为对象。当您向右/向左移动时,它将为您提供当前位置,您只需要使用此位置从列表对象中获取记录

例如

您的 POJO 类将存储数据 MyData.java

public class MyData{
    public long id = -1;
    public String name = "";
    public String description = "";
    public String imagePath = ""; /// I don't know you want exactly, you need to implement image as per your requirement.
}

在你的活动中

private List<MyData> myList = new ArrayList<MyData>();


oncreate(){

fetchData(); // you need to implement this in AsyncTask so UI was not block just implement AsyncTask and call this method in doInBackground().

// after this you can implment View flipper and add view and set the data by fetch the list object using current view flipper position.

}

private void fetchData(){

    while (cursor.moveToNext()){
         MyData myData = new MyData();
         myData.id = cursor.getLong(0);
         myData.desc=cursor.getString(1);
         myData.name = cursor.getString(5);
         list.add(myData);
         myData = null;
    }

}
于 2013-01-03T06:23:52.463 回答