How to create a custom navigation drawer in android

The tutorial Android Custom Navigation Drawer (via archive.org) contains a basic and a custom project. The latter shows how to setup a Navigation Drawer as shown in the screenshot: The source code of the projects (via archive.org) is available for download. The is also the Navigation Drawer – Live-O project … The source code of … Read more

setVisibility(GONE) view becomes invisible but still occupies space

This is an Android bug in my opinion, we just fix this issue doing this: <FrameLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <LinearLayout android:id=”@+id/layout_to_hide” android:layout_width=”match_parent” android:layout_height=”wrap_content”> //Put here your views </LinearLayout> </FrameLayout> Just hide LinearLayout with id LAYOUT_TO_HIDE with Visible.GONE and then root FrameLayout will collapse its height giving you a “hidden” with non-blank-space header.

Detect Scroll Up & Scroll down in ListView

try using the setOnScrollListener and implement the onScrollStateChanged with scrollState setOnScrollListener(new OnScrollListener(){ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub } public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO Auto-generated method stub final ListView lw = getListView(); if(scrollState == 0) Log.i(“a”, “scrolling stopped…”); if (view.getId() == … Read more

Android ListView Selector Color

The list selector drawable is a StateListDrawable — it contains reference to multiple drawables for each state the list can be, like selected, focused, pressed, disabled… While you can retrieve the drawable using getSelector(), I don’t believe you can retrieve a specific Drawable from a StateListDrawable, nor does it seem possible to programmatically retrieve the … Read more

Non-scrollable ListView inside ScrollView

You Create Custom ListView Which is non Scrollable public class NonScrollListView extends ListView { public NonScrollListView(Context context) { super(context); } public NonScrollListView(Context context, AttributeSet attrs) { super(context, attrs); } public NonScrollListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec( Integer.MAX_VALUE >> … Read more

Android custom Row Item for ListView

Add this row.xml to your layout folder <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Header”/> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/text”/> </LinearLayout> make your main xml layout as this <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:orientation=”horizontal” > <ListView android:id=”@+id/listview” android:layout_width=”fill_parent” android:layout_height=”fill_parent” > </ListView> </LinearLayout> This is your adapter class yourAdapter extends … Read more

android – listview get item view by position

Use this : public View getViewByPosition(int pos, ListView listView) { final int firstListItemPosition = listView.getFirstVisiblePosition(); final int lastListItemPosition = firstListItemPosition + listView.getChildCount() – 1; if (pos < firstListItemPosition || pos > lastListItemPosition ) { return listView.getAdapter().getView(pos, null, listView); } else { final int childIndex = pos – firstListItemPosition; return listView.getChildAt(childIndex); } }

Android ListView selected item stay highlighted

I found the proper way. It’s very simple. In resource describe following: android:choiceMode=”singleChoice” android:listSelector=”#666666″ (or you may specify a resource link instead of color value) Programmatical: listView.setSelector(Drawable selector); listView.setSelector(int resourceId); listView.setChoiceMode(int mode); mode can be one of these: AbsListView.CHOICE_MODE_SINGLE, AbsListView.CHOICE_MODE_MULTIPLE, AbsListView.CHOICE_MODE_NONE (default) (AbsListView is the abstract ancestor for the ListView class) P.S. manipulations with onItemClick … Read more