从sqlite的数据转换成ArrayList中<串GT; [英] data from sqlite into ArrayList<String>

查看:200
本文介绍了从sqlite的数据转换成ArrayList中<串GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用code <一个href=\"http://from%20http://ericharlow.blogspot.com/2010/10/experience-android-drag-and-drop-list.html\"相对=nofollow>这个博客有一个可拖动列表。本教程使用自定义DragNDropAdapter
这需要的内容作为一个ArrayList

在我listActivity我查询与返回的列名称。具有插入11值的表。
我试图从它的String []有很多方法,如转换为ArrayList的:

 的String [] =由新的String [] {} DbManager.KEY_NAME;
 ArrayList的&LT;串GT;内容=新的ArrayList&LT;串GT;(); 的for(int i = -1,L = from.length ++ I&LT;升;){
            content.add(从[I]);
            //Log.i(\"ArrayList,由[I]);
        }

 而(!mShopCatCursor.isAfterLast()){
         content.add(mShopCatCursor.getString(0));
     }

我得到的是与列的只是名字,名称列表。
你有什么想法


解决方案

 的String [] =由新的String [] {} DbManager.KEY_NAME;

由于您的字符串数组只有一个值,它是KEY_NAME。

您需要做的是,

使用循环从游标获取价值观和填充它的String [以上。

 光标userCur = adaptor.getYourData();
            如果(userCur!= NULL){
                的String [] = strArr新的String [userCur.getCount()];
                startManagingCursor(userCur);
                如果(userCur.moveToFirst()){
                    诠释计数= 0;
                    做{
                        字符串username = userCur.getString(1);
                        strArr [计数] = userName.trim();
                        算上++;
                    }而(userCur.moveToNext());
                }ArrayList的&LT;串GT;内容=新的ArrayList&LT;串GT;();
               的for(int i = -1,L = from.length ++ I&LT;升;){
                content.add(从[I]);
      //Log.i(\"ArrayList,由[I]);
     }
}

请注意:我还没有在IDE中验证这一点,有可能是语法错误。

i am using code this blog to have a draggable list. This tutorial is using a custom DragNDropAdapter that takes the content as an ArrayList.

In my listActivity i query a table with returned column name.It has 11 values inserted. i tried to convert it to ArrayList from String[] with many ways such as :

 String[] from = new String[]{DbManager.KEY_NAME};
 ArrayList<String> content = new ArrayList<String>();

 for (int i=-1,l=from.length; ++i<l;) {
            content.add(from[i]);
            //Log.i("ArrayList", from[i]);
        }

or

 while(!mShopCatCursor.isAfterLast()){
         content.add(mShopCatCursor.getString(0));
     }

what i get is a list with just the name of the column, name. do you have any ideas

解决方案

String[] from = new String[]{DbManager.KEY_NAME};

Because your string array has only one value which is KEY_NAME.

What you need to do is,

Get values from Cursor using loop and populate it String[] above.

Cursor userCur = adaptor.getYourData();
            if (userCur != null) {
                String[] strArr = new String[userCur.getCount()];
                startManagingCursor(userCur);
                if (userCur.moveToFirst()) {
                    int count = 0;
                    do {
                        String userName = userCur.getString(1);
                        strArr[count] = userName.trim();
                        count++;
                    } while (userCur.moveToNext());
                }

ArrayList<String> content = new ArrayList<String>();  
               for (int i=-1,l=from.length; ++i<l;) {    
                content.add(from[i]);              
      //Log.i("ArrayList", from[i]);           
     }                  
}

Note: I haven't validated this in IDE, there may be syntax errors.

这篇关于从sqlite的数据转换成ArrayList中&LT;串GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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