Skip to content

example from using listfragment helper to speed up your task

世外桃源 edited this page May 22, 2015 · 2 revisions

this is not too useful if u copy everything from this example, but this will give you the idea how to work with the listfragment abstract

The library or things to prepare...

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hkm.disqus.api.ApiClient;
import com.hkm.disqus.api.exception.ApiException;
import com.hkm.disqus.api.model.Response;
import com.hkm.disqus.api.model.posts.Post;
import com.hkm.editorial.disqusapi.adapterDisqusComments;
import com.hkm.editorial.life.LifeCycleApp;
import com.marshalchen.ultimaterecyclerview.UltimateRecyclerView;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import retrofit.Callback;
import retrofit.RetrofitError;

The content...

/**
 * Created by hesk on 30/4/15.
 *
 * @resources https://www.temboo.com/library/Library/Disqus/Threads/ListPosts/
 */
public class disquscomment extends listFragment implements Callback<Response<List<Post>>> {
    public final static String
            IDENTIFER = "ID",
            POS = "PAGEPOS",
            LOADURL = "LOAD",
            TAG = "DISQUSCOMMENTS";


    /**
     * Static factory method that takes an int parameter,
     * initializes the fragment's arguments, and returns the
     * new fragment to the client.
     */
    public static disquscomment newInstance(String thread_id) {
        disquscomment t = new disquscomment();
        Bundle b = new Bundle();
        b.putString(IDENTIFER, thread_id);
        t.setArguments(b);
        return t;
    }
    private ArrayList<Post> list = new ArrayList<>();
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ApiClient r = ((LifeCycleApp) getActivity().getApplication()).getDisqusClient();
        try {
            String thread_Id = getArguments().getString(IDENTIFER);
            r.createThreads().listPostByIDAsync(thread_Id, "mycompanyforumname", this);
        } catch (ApiException e) {

        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void success(com.hkm.disqus.api.model.Response<List<Post>> p, retrofit.client.Response res) {
        Log.d(TAG, "now its working now");
        list.clear();
        list.addAll(p.data);
        getAdapter().notifyDataSetChanged();
    }


    @Override
    public void failure(RetrofitError error) {
        Log.d(TAG, error.getMessage());
    }


    @Override
    protected ArrayList<Post> getListSource() {
        return list;
    }

    @Override
    protected adapterDisqusComments getAdapter() {
        return new adapterDisqusComments(getListSource());
    }

    @Override
    protected void configUltimateRecyclerView(UltimateRecyclerView listview) {

    }
}
Clone this wiki locally