如何在Android中使用ViewFlipper显示来自SQLite的内容 [英] How to display content from sqlite using ViewFlipper in android

查看:123
本文介绍了如何在Android中使用ViewFlipper显示来自SQLite的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情况我有3条在sqlite的这些人获取来自websercive包含ID,名称,描述和图片现在我想翻转第一record.and 3中第二个记录后后显示的第一条记录和第二翻转..

In my scenario i am having 3 records in sqlite which were fetched from websercive that contains id,name,description and image now i want to display the first record and second one after flipping the first record.and 3 one after second record flips..

我迄今所做的是

  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;
            }
        });

我能够显示当我设置打破第一条记录数据;声明否则显示的是最后一个记录data..How可以继续这种做法?

I am able to display first record data when i set break; statement otherwise it is displaying last record data..How can proceed for this approach?

推荐答案

第一次提取的所有的记录和存储目录< YourDataClass>从onCreate方法myList上对象。正如我刚才给你的例子

First fetch all the records and store in List<YourDataClass> myList object from onCreate method. As I have just giving you the examples

现在获取数据,并存储在你的清单对象后,您需要执行的鳍状肢的变化事件,所以当脚蹼是变化获取当前位置,并使用该位置获取数据从你的清单对象的对象。当您移动左/右,将让你的当前位置,你只需要使用这个位置来从列表对象中的记录

Now after fetching the data and stored in your list object you need to implement flipper change event so when flipper was change get the current position and using this position get the data as object from your list object. As you move right/left it will giving you the current position and you just need to use this position to fetch the records from list object

例如

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

Your POJO class will store the data 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;
    }

}

这篇关于如何在Android中使用ViewFlipper显示来自SQLite的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆