ClassCastException when calling ListView.addHeaderView()?

FrameLayout and AbsListView convert their children layout params to FrameLayout.LayoutParams and AbsListView.LayoutParams. This is where the casting fails. View header = View.inflate(this, R.layout.header_layout, null); should fix it. Edit: As mentioned in the comments, changing the ViewGroup Parameter of the inflate call also makes it work: header = inflater.inflate(R.layout.header_layout, null, false);

Remove ListView items in Android

You will want to remove() the item from your adapter object and then just run the notifyDatasetChanged() on the Adapter, any ListViews will (should) recycle and update on it’s own. Here’s a brief activity example with AlertDialogs: adapter = new MyListAdapter(this); lv = (ListView) findViewById(android.R.id.list); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> a, View v, … Read more

ListView item scroll animation (“UIKit Dynamics” -like)

This implementation works quite good. There is some flickering though, probably because of altered indices when the adapter add new views to top or bottom..That could be possibly solved by watching for changes in the tree and shifting the indices on the fly.. public class ElasticListView extends GridView implements AbsListView.OnScrollListener, View.OnTouchListener { private static int … Read more

EditText in Listview loses focus when pressed on Android 4.x

A classic hack for situations like this is to use a handler and postDelayed(). In your adapter: private int lastFocussedPosition = -1; private Handler handler = new Handler(); public View getView(final int position, View convertView, ViewGroup parent) { // … edittext.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { handler.postDelayed(new … Read more

Endless RecyclerView with ProgressBar for pagination

HERE IS SIMPLER AND CLEANER APPROACH. Implement Endless Scrolling from this Codepath Guide and then follow the following steps. 1. Add progress bar under the RecyclerView. <android.support.v7.widget.RecyclerView android:id=”@+id/rv_movie_grid” android:layout_width=”0dp” android:layout_height=”0dp” android:paddingBottom=”50dp” android:clipToPadding=”false” android:background=”@android:color/black” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent”> </android.support.v7.widget.RecyclerView> <ProgressBar android:id=”@+id/progressBar” style=”?android:attr/progressBarStyle” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:visibility=”invisible” android:background=”@android:color/transparent” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” /> Here android:paddingBottom=”50dp” and android:clipToPadding=”false” are very … Read more