Programmatically scroll to a specific position in an Android ListView
For a direct scroll: getListView().setSelection(21); For a smooth scroll: getListView().smoothScrollToPosition(21);
For a direct scroll: getListView().setSelection(21); For a smooth scroll: getListView().smoothScrollToPosition(21);
In your public View getView method change return null; to return convertView;.
Here is one way of doing it (Thanks to Android Documentation though!): Add the following into a file (say customshape.xml) and then place it in (res/drawable/customshape.xml) <?xml version=”1.0″ encoding=”UTF-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle”> <gradient android:startColor=”#SomeGradientBeginColor” android:endColor=”#SomeGradientEndColor” android:angle=”270″/> <corners android:bottomRightRadius=”7dp” android:bottomLeftRadius=”7dp” android:topLeftRadius=”7dp” android:topRightRadius=”7dp”/> </shape> Once you are done with creating this file, just set the background in … Read more
As Faizan describes in their answer here: First of all read the Json File from your assests file using below code. and then you can simply read this string return by this function as public String loadJSONFromAsset() { String json = null; try { InputStream is = getActivity().getAssets().open(“yourfilename.json”); int size = is.available(); byte[] buffer = … Read more
Add this to your xml: android:listSelector=”@android:color/transparent” And for the problem this may work (I’m not sure and I don’t know if there are better solutions): You could apply a ColorStateList to your TextView.
Here’s my solution. I’m fairly new to the Android platform, and I’m sure this is a bit hackish, especially in the part about calling .measure directly, and setting the LayoutParams.height property directly, but it works. All you have to do is call Utility.setListViewHeightBasedOnChildren(yourListView) and it will be resized to exactly accommodate the height of its … Read more
@Asahi pretty much hit the nail on the head, but I just wanted to add a bit of XML for anyone maybe floating in here later via google: <ListView android:id=”@+id/MyListView” android:layout_height=”match_parent” android:layout_width=”match_parent” android:divider=”@android:color/transparent” android:dividerHeight=”10.0sp”/> For some reason, values such as “10”, “10.0”, and “10sp” all are rejected by Android for the dividerHeight value. It wants … Read more
You can set this value in a layout xml file using android:divider=”#FF0000″. If you are changing the colour/drawable, you have to set/reset the height of the divider too. <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content”> <ListView android:id=”@+id/android:list” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:divider=”#FFCC00″ android:dividerHeight=”4px”/> </LinearLayout>
Try this: // save index and top position int index = mList.getFirstVisiblePosition(); View v = mList.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() – mList.getPaddingTop()); // … // restore index and position mList.setSelectionFromTop(index, top); Explanation: ListView.getFirstVisiblePosition() returns the top visible list item. But this item may be partially scrolled out of view, … Read more
Call notifyDataSetChanged() on your Adapter object once you’ve modified the data in that adapter. Some additional specifics on how/when to call notifyDataSetChanged() can be viewed in this Google I/O video.