Note that there are some explanatory texts on larger screens.

plurals
  1. POcwac Endless Fragment Demo Issue - Using Within My Own Fragment Format
    primarykey
    data
    text
    <p>I have a basic working app generated by using the ADT wizard. As a result I have a basic fragment format (1 ) which I have been using.</p> <p>I want to take the demo code (2) and use it how ever if I take the fragment example as is the application crashes and the logcat shows the fragment as the fault.</p> <p>I have tried to take the code from (1) and (2) to create (3) how ever multiple errors occur. After so looking I believe that the issue is with "DemoAdapter adapter=null;" because for what ever reason "class DemoAdapter extends EndlessAdapter implements IItemsReadyListener" is not visible to call.</p> <p>T</p> <p>(1)My basic fragment - Which works</p> <pre><code>import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Fragment2 extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_dod_events, container, false); // Do Stuff Here return root; } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // Save some state! } } </code></pre> <p>(2)The Endless Demo - No Errors but crashes my app if I use as is....</p> <pre><code>package com.commonsware.cwac.endless.demo; import android.app.ListFragment; import android.os.AsyncTask; import android.os.Bundle; import android.os.SystemClock; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ArrayAdapter; import java.util.ArrayList; import com.commonsware.cwac.endless.EndlessAdapter; /** * This example makes use of EndlessAdapter's * setRunInBackground feature. * * Calling setRunInBackground(false) allows you to launch * your own AsyncTask with a listener callback, rather than * using the built in cacheInBackground functionality. * * This is useful if you have existing AsyncTask(s) written * to fetch data in a background thread, and don't want * EndlessAdapter launching that in yet another background * thread. */ public class EndlessAdapterCustomTaskFragment extends ListFragment { DemoAdapter adapter=null; ArrayList&lt;Integer&gt; items=null; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); if (adapter == null) { items=new ArrayList&lt;Integer&gt;(); for (int i=0; i &lt; 25; i++) { items.add(i); } adapter=new DemoAdapter(items); adapter.setRunInBackground(false); // Tell the adapter // we will handle // starting the // background task } setListAdapter(adapter); } class DemoAdapter extends EndlessAdapter implements IItemsReadyListener { private RotateAnimation rotate=null; DemoAdapter(ArrayList&lt;Integer&gt; list) { super(new ArrayAdapter&lt;Integer&gt;(getActivity(), R.layout.row, android.R.id.text1, list)); rotate= new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(600); rotate.setRepeatMode(Animation.RESTART); rotate.setRepeatCount(Animation.INFINITE); } @Override protected View getPendingView(ViewGroup parent) { View row= getActivity().getLayoutInflater().inflate(R.layout.row, null); View child=row.findViewById(android.R.id.text1); child.setVisibility(View.GONE); child=row.findViewById(R.id.throbber); child.setVisibility(View.VISIBLE); child.startAnimation(rotate); return(row); } @Override protected boolean cacheInBackground() throws Exception { new FetchDataTask(this, items.size()).execute(); return(items.size()&lt;75); } @Override public void onItemsReady(ArrayList&lt;Integer&gt; data) { items.addAll(data); adapter.onDataReady(); // Tell the EndlessAdapter to // remove it's pending // view and call // notifyDataSetChanged() } @Override protected void appendCachedData() { } } interface IItemsReadyListener { public void onItemsReady(ArrayList&lt;Integer&gt; data); } class FetchDataTask extends AsyncTask&lt;Void, Void, ArrayList&lt;Integer&gt;&gt; { IItemsReadyListener listener; /* * The point from where to start counting. In a real * life scenario this could be a pagination number */ int startPoint; protected FetchDataTask(IItemsReadyListener listener, int startPoint) { this.listener=listener; this.startPoint=startPoint; } @Override protected ArrayList&lt;Integer&gt; doInBackground(Void... params) { ArrayList&lt;Integer&gt; result=new ArrayList&lt;Integer&gt;(); SystemClock.sleep(3000); // pretend to do work for (int i=startPoint; i &lt; startPoint + 25; i++) { result.add(i); } return(result); } @Override protected void onPostExecute(ArrayList&lt;Integer&gt; result) { listener.onItemsReady(result); } } } </code></pre> <p>(3)My new fragment using both the above which does not work.</p> <pre><code>import java.util.ArrayList; import android.os.AsyncTask; import android.os.Bundle; import android.os.SystemClock; import android.support.v4.app.Fragment; import android.support.v4.app.ListFragment; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.widget.ArrayAdapter; import com.commonsware.cwac.endless.EndlessAdapter; public class Fragment2 extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_dod_events, container, false); DemoAdapter adapter=null; ArrayList&lt;Integer&gt; items=null; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); if (adapter == null) { items=new ArrayList&lt;Integer&gt;(); for (int i=0; i &lt; 25; i++) { items.add(i); } adapter=new DemoAdapter(items); adapter.setRunInBackground(false); // Tell the adapter // we will handle // starting the // background task } setListAdapter(adapter); } class DemoAdapter extends EndlessAdapter implements IItemsReadyListener { private RotateAnimation rotate=null; DemoAdapter(ArrayList&lt;Integer&gt; list) { super(new ArrayAdapter&lt;Integer&gt;(getActivity(), R.layout.row, android.R.id.text1, list)); rotate= new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(600); rotate.setRepeatMode(Animation.RESTART); rotate.setRepeatCount(Animation.INFINITE); } @Override protected View getPendingView(ViewGroup parent) { View row= getActivity().getLayoutInflater().inflate(R.layout.row, null); View child=row.findViewById(android.R.id.text1); child.setVisibility(View.GONE); child=row.findViewById(R.id.throbber); child.setVisibility(View.VISIBLE); child.startAnimation(rotate); return(row); } @Override protected boolean cacheInBackground() throws Exception { new FetchDataTask(this, items.size()).execute(); return(items.size()&lt;75); } @Override public void onItemsReady(ArrayList&lt;Integer&gt; data) { items.addAll(data); adapter.onDataReady(); // Tell the EndlessAdapter to // remove it's pending // view and call // notifyDataSetChanged() } @Override protected void appendCachedData() { } } interface IItemsReadyListener { public void onItemsReady(ArrayList&lt;Integer&gt; data); } class FetchDataTask extends AsyncTask&lt;Void, Void, ArrayList&lt;Integer&gt;&gt; { IItemsReadyListener listener; /* * The point from where to start counting. In a real * life scenario this could be a pagination number */ int startPoint; protected FetchDataTask(IItemsReadyListener listener, int startPoint) { this.listener=listener; this.startPoint=startPoint; } @Override protected ArrayList&lt;Integer&gt; doInBackground(Void... params) { ArrayList&lt;Integer&gt; result=new ArrayList&lt;Integer&gt;(); SystemClock.sleep(3000); // pretend to do work for (int i=startPoint; i &lt; startPoint + 25; i++) { result.add(i); } return(result); } @Override protected void onPostExecute(ArrayList&lt;Integer&gt; result) { listener.onItemsReady(result); } } // Do Stuff Here return root; } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // Save some state! } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload