Remove all items from RecyclerView

This works great for me: public void clear() { int size = data.size(); if (size > 0) { for (int i = 0; i < size; i++) { data.remove(0); } notifyItemRangeRemoved(0, size); } } Source: https://github.com/mikepenz/LollipopShowcase/blob/master/app/src/main/java/com/mikepenz/lollipopshowcase/adapter/ApplicationAdapter.java or: public void clear() { int size = data.size(); data.clear(); notifyItemRangeRemoved(0, size); } For you: @Override protected void onRestart() … Read more

adapter-Any real example of Adapter Pattern [closed]

Many examples of Adapter are trivial or unrealistic (Rectangle vs. LegacyRectangle, Ratchet vs. Socket, SquarePeg vs RoundPeg, Duck vs. Turkey). Worse, many don’t show multiple Adapters for different Adaptees (someone cited Java’s Arrays.asList as an example of the adapter pattern). Adapting an interface of only one class to work with another seems a weak example … Read more

How to show installed app list in a listview without Checkbox getting unchecked when listview is scrolled?

Activity import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.pm.PackageInfo; import android.os.Bundle; import android.widget.ListView; public class AppScreen extends Activity { private ListView list; ArrayList<Datamodel> res; MyAdapter _adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.app_screen); list = (ListView) findViewById(R.id.list); List<PackageInfo> _myapps = getPackageManager().getInstalledPackages(0); res = new ArrayList<Datamodel>(); for (int i = 0; i < _myapps.size(); i++) … Read more

ListView Viewholder checkbox state

Here’s how I made it work: First, you need a separate array for your checked state. It has to be the same size as your adapter’s getCount(). Then on your getView, your checkbox’s setOnCheckedChangedListener MUST PRECEED your checkbox.setChecked statements. example: holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { isChecked[position] = isChecked; } … Read more

What’s the purpose of item-id’s in Android ListView Adapter?

Imagine this structure: You have db table Notes with such 3 records: +—-+————————–+ | ID | Note Text | +—-+————————–+ | 43 | Note text blah blah | | 67 | Note text blah blah blah | | 85 | Last note | +—-+————————–+ and you implement an adapter to serve this data. Now let’s … Read more

tech