Skip to content Skip to sidebar Skip to footer

Pass A List From A Fragment To A Class

I have a fragment which present a list to the user, so I have inside the class extends fragment, 2 classes : one for the Holder and other for the Adapter. public class ListFragment

Solution 1:

I found the solution: Use the databse SQLite. Once you've created and implemented it you need to call it from the service of the widget (inside RemoteViewFactory) records is an Arraylist of string:

NoteBaseHelper db = new NoteBaseHelper(this.mContext);
    NoteBaseHelper mDbHelper = new NoteBaseHelper(this.mContext);

    NoteHolder nh = new NoteHolder(this.mContext);

    myListTitle=nh.getNotes();
    records=new ArrayList<String>();

    for (Note e: myListTitle){
        records.add(e.getTitle().toString());
    }

Then you can set up your views in the method getViewAt :

public RemoteViews getViewAt(int position) {

    // position will always range from 0 to getCount() - 1.
    // Construct a RemoteViews item based on the app widget item XML file, 
    and set the
    // text based on the position.
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), 
R.layout.widget_item);
    // feed row
    String data=records.get(position);
    String title = myListTitle.get(position).getTitle();
    String details = myListTitle.get(position).getDetails();
    //Put data in the widget list
    rv.setTextViewText(R.id.title, data);
    rv.setTextViewText(R.id.details, details);

Post a Comment for "Pass A List From A Fragment To A Class"