0

i want convert data from corsor to String [] array for i can change this static class to dynamic i want use my cols in place of imageResIds and imageTitles that it s the static class

public class StaticImageData {
    private static ImageItem[] mImageItemArray;

    private static int[] imageResIds = {R.drawable.android,
        R.drawable.hamburger, R.drawable.globe, R.drawable.notepad,
        R.drawable.play, R.drawable.sun, R.drawable.tux, R.drawable.yawn};
    private static String[] imageTitles = {"Android", "Burger", "Globe",
        "Note Pad", "Play", "Sun", "Tux", "Yahh!"};

    /**
     * Default image to show
     */
    public static final int DEFAULT_IMAGE_INDEX = 0;

    /**
     * @return static instance of the image item array
     */
    public static ImageItem[] getImageItemArrayInstance() {
        if (mImageItemArray == null) {
            mImageItemArray = new ImageItem[imageResIds.length];

            for (int i = 0; i < mImageItemArray.length; i++) {
                ImageItem imageItem = new ImageItem(imageTitles[i], imageResIds[i]);
                mImageItemArray[i] = imageItem;
            }
        }
        return mImageItemArray;
    }



}

that it s the getall() from my db

public  VerbItem[] getAllVerbs() {
    final SQLiteDatabase db = MyDbHelper.getReadableDatabase();
    Cursor cursor = null;
    ArrayList<VerbItem> myverbs = new ArrayList<VerbItem>();
    try {
        cursor = db.query(MyTables.TABLE_VERBS,
                          VerbsQuery.PROJECTION,
                          null, null, null, null, null);
        if (cursor.moveToFirst()) {
            do {
                VerbItem page = new VerbItem(
                                     cursor.getInt(VerbsQuery.TAG_ID_VERB_COL),
                                     cursor.getInt(VerbsQuery.TAG_ID_PAGE_COL),
                                     cursor.getString(VerbsQuery.TAG_VERB_COL),
                                     cursor.getString(VerbsQuery.TAG_TEMP1_COL),
                                     cursor.getString(VerbsQuery.TAG_TEMP2_COL),
                                     cursor.getString(VerbsQuery.TAG_TEMP3_COL),
                                     cursor.getString(VerbsQuery.TAG_TRAD_COL),
                                     cursor.getString(VerbsQuery.TAG_EXEMPL_COL),
                                     cursor.getString(VerbsQuery.TAG_V_IMAG_COL),
                                     cursor.getString(VerbsQuery.TAG_VAR1_COL));
                myverbs.add(page);
            } while (cursor.moveToNext());
        }

        VerbItem.setCount(cursor.getCount());

        Log.i(TAG, "c: "+ cursor.getCount());

        return myverbs.toArray(new VerbItem[myverbs.size()]);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}



      public interface VerbsQuery {
            int _TOKEN = 0x4;
        String TBN = MyTables.TABLE_VERBS;

            String[] PROJECTION = {
                    MyTables.ID_VERB_COL,
                    MyTables.ID_PAGE_COL,
                    MyTables.VERB_COL,
                    MyTables.TEMP1_COL,
                    MyTables.TEMP2_COL,
                    MyTables.TEMP3_COL,
                    MyTables.TRAD_COL,
                    MyTables.EXEMPL_COL,
                    MyTables.V_IMAG_COL,
                    MyTables.VAR1_COL,
            };

            int TAG_ID_VERB_COL = 0;
            int TAG_ID_PAGE_COL = 1;
            int TAG_VERB_COL = 2;
            int TAG_TEMP1_COL = 3;
            int TAG_TEMP2_COL = 4;
            int TAG_TEMP3_COL = 5;
            int TAG_TRAD_COL = 6;
            int TAG_EXEMPL_COL = 7;
            int TAG_V_IMAG_COL =8;
            int TAG_VAR1_COL =9;
        }



    }

i have try that but allways java.lang.NullPointerException

public List<FeedPage> getAllPagess() {
         SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();

        Cursor cursor = null;
        List<FeedPage> feedpages = new ArrayList<FeedPage>();

        cursor = db.query(FeedContract.Entry.TABLE_NAME,
                new String[] {FeedContract.Entry.COLUMN_NAME_ENTRY_ID, FeedContract.Entry.COLUMN_NAME_TITLE, FeedContract.Entry.COLUMN_NAME_LINK, FeedContract.Entry.COLUMN_IMAG_LINK,FeedContract.Entry.COLUMN_TEXT_ENTRY,FeedContract.Entry.COLUMN_NAME_PUBLISHED},
                null, null, null, null, FeedContract.Entry.COLUMN_NAME_PUBLISHED + " desc");

        cursor.moveToFirst();

        while (!cursor.isAfterLast()) {

            FeedPage feedpage = new FeedPage();

            feedpage.setId(cursor.getInt(TAG_ID));
            feedpage.setTitle(cursor.getString(TAG_TITLE).toString());
            feedpage.setLink(cursor.getString(TAG_LINK).toString());
            feedpage.setImaglink(cursor.getString(TAG_IMAG_LINK).toString());
            feedpage.setTextentry(cursor.getString(TAG_TEXT_ENTRY).toString());
            feedpage.setPublished(cursor.getLong(TAG_PUBLISHED));

            Log.d(TAG, "get comment = " + cursorToComment(cursor).toString());
            feedpages.add(feedpage);
            cursor.moveToNext();
        }
        // Make sure to close the cursor
        cursor.close();
        return feedpages;
    }
4
  • Basically what you need is a Map of String to your Image Resources? Mar 11, 2014 at 2:56
  • no im using une util imagloader i can get the image from them name Mar 11, 2014 at 3:02
  • im looking to change all columns Mar 11, 2014 at 3:04
  • i think i dont need to keep the imageResIds like ID i dont know for what that help !!! i meane if i will change the arraylist i dont need it Mar 11, 2014 at 3:17

1 Answer 1

0

You can try to load the files from the file name in your resources, something like this:

public Drawable getDrawableFromString(String myFaleName){
     Resources res = getResources();
     int resID = res.getIdentifier(myFaleName, "drawable", getPackageName());
     Drawable drawable = res.getDrawable(resID );
     return drawable;
}
7
  • exactly but it not that the problem the query dont find any from db Mar 11, 2014 at 3:09
  • if the query don't find nothing from DB the problem can be in your query :) , can you add the query on your question? (also the script that create the table), another thing... are you sure you have data on your database? Mar 11, 2014 at 3:16
  • yes i can see the db is created and data is insered Mar 11, 2014 at 3:22
  • there it s the source in the tuto Mar 11, 2014 at 3:25
  • www.captechconsulting.com/blog/steven-byle/android-tutorial-optimizing-phones-and-tablets-fragments[link] Mar 11, 2014 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.