How to modify dummy content in activity and /

I would modify the elements created by eclipse in the master / detail schema. I cannot find a way to do this. In particular, I would take elements from the xml resource file (res / values ​​/ arrays).

this is java file:

package com.ga.termeapp.dummy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class DummyContent {

    public static class DummyItem {

        public String id;
        public String content;

        public DummyItem(String id, String content) {
            this.id = id;
            this.content = content;
        }

        @Override
        public String toString() {
            return content;
        }
    }

    public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();
    public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();

    static {

        addItem(new DummyItem("1", "Le terme"));
        addItem(new DummyItem("2", "Le cure termali"));
        addItem(new DummyItem("3", ""));
    }

    private static void addItem(DummyItem item) {
        ITEMS.add(item);
        ITEM_MAP.put(item.id, item);
    }
}
+5
source share
3 answers

Possible Solution:

Replace the static class with your own. In my case, DummyItemit becomes ProfileItemand has different attributes, but DummyContentit becomes ProfileListContent.

Then replace the static block with the static { addItem ... }static method. In the following case, I need to load items from the database:

public static void setContext(Context c) {
    if (db == null) db = new MyDbAdapter(c); // SQLiteOpenHelper + SQLiteDatabase manager
    if (db.isOpen() == false) {
        db.open();
        Cursor c = db.getProfiles(); // database query
        if (c.moveToFirst()) {
            do {
                ProfileItem item = new ProfileItem(c.getString(0), c.getString(1),
                    c.getString(2));
                addItem(item);
            } while (c.moveToNext());
        }
    }
}

I call the method setContextfrom my main action at the beginning of the method onCreatebefore any other operation.

public void onCreate(Bundle savedInstanceState) {
    ProfileListContent.setContext(this);
    ...

:

public static void insertProfile(ProfileItem profile) {
    db.insertProfile(profile); // add item to the database
    addItem(profile); // the same addItem provided with the eclipse wizard
}

, , ListView, .

+5

, ,

addItem(new DummyItem("1", "Le terme"));
addItem(new DummyItem("2", "Le cure termali"));
addItem(new DummyItem("3", ""));

addItem, , , .

    public String id;
    public String content;

    public DummyItem(String id, String content) {
        this.id = id;
        this.content = content;

, .

0

, , , . ItemListActivity.java Oncreate

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (DummyContent.ITEMS.isEmpty())
    {
        DummyContent.addItem(new DummyItem("1", getResources().getString(R.string.menu1)));
        DummyContent.addItem(new DummyItem("2", getResources().getString(R.string.menu2)));
        DummyContent.addItem(new DummyItem("3", getResources().getString(R.string.menu3)));
    }

,

0

All Articles