Reputation: 11782
I am using following code for my ListView..
My FragmentActivity
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.home, container, false);
listView = (ListView) view.findViewById(R.id.listView);
listView.setAdapter(new CustomArrayAdapterForHome(mContext,questions));
return view;
}
Here is the Adapter for ListView
@SuppressLint("DefaultLocale")
public class CustomArrayAdapterForHome extends EndlessAdapter
{
private final LayoutInflater inflator;
protected ImageLoader imageLoader;
private DisplayImageOptions options;
private RotateAnimation rotate=null;
private View pendingView = null;
public CustomArrayAdapterForHome(Context ctx,ArrayList<Question> questionList)
{
super( new ArrayAdapter<Question>(ctx, R.layout.question_adapter_layout, questionList));
inflator = mContext.getLayoutInflater();
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.showImageForEmptyUri(R.drawable.user_male)
.displayer(new RoundedBitmapDisplayer(5))
.build();
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);
}
class ViewHolder
{
// MY CODE
}
@Override
public int getCount() {
return questions.size();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final Question question = questions.get(position);
final OpenionUser myUser = question.getUser();
// MY CODE
return view;
}
@Override
protected View getPendingView(ViewGroup parent)
{
View row = LayoutInflater.from(parent.getContext()).inflate(R.layout.row, null);
pendingView = row.findViewById(android.R.id.text1);
pendingView.setVisibility(View.GONE);
pendingView=row.findViewById(R.id.throbber);
pendingView.setVisibility(View.VISIBLE);
startProgressAnimation();
return(row);
}
private void startProgressAnimation()
{
if (pendingView!=null)
{
pendingView.startAnimation(rotate);
}
}
@Override
protected void appendCachedData()
{
}
@Override
protected boolean cacheInBackground() throws Exception
{
getQuestions();
return true;
}
}
The above code is just behaving like simple ListView, cacheInBackground Or getPendingView are not getting called. FurtherMore I want to add a headerView too and its not working either.
What am I missing in this?
Upvotes: 0
Views: 152
Reputation: 1006869
Most of the code that you have here does not belong in an EndlessAdapter
. Quoting the documentation:
It is designed to wrap around another adapter, where you have your "real" data. Hence, it follows the Decorator pattern, augmenting your current adapter with new Endless Technology(TM).
So, first, create a regular ArrayAdapter
, and get all the styling and stuff that you want (e.g., your getView()
implementation). Then, create an EndlessAdapter
subclass that adds in the "endlessness".
Of note:
An EndlessAdapter
subclass should not override getView()
, as that is where the endless behavior is added
An EndlessAdapter
subclass should not override getCount()
, as that is managed by the EndlessAdapter
implementation itself
You may wish to examine the sample app to see how it implements EndlessAdapter
subclasses.
Or, since EndlessAdapter
will not work with header views, you may simply need to switch to a different endless list solution or roll your own.
Upvotes: 1