Skip to main content

Posts

Showing posts with the label listview

how to use overscroll functionality for listview?

Android's new Overscroll functionality introduced in Gingerbread and discovered some more interesting things. The functionality to make a a view scroll beyond its limits and then bounce back (almost exactly like iOS) is sort of built into the framework, but just hidden. http://www.youtube.com/watch?v=dOyWCDhlxv8&feature=player_embedded Source: Tips4all

ArrayIndexOutOfBoundsException with custom Android Adapter for multiple views in ListView

I am attempting to create a custom Adapter for my ListView since each item in the list can have a different view (a link, toggle, or radio group), but when I try to run the Activity that uses the ListView I receive an error and the app stops. The application is targeted for the Android 1.6 platform. The code: public class MenuListAdapter extends BaseAdapter { private static final String LOG_KEY = MenuListAdapter.class.getSimpleName(); protected List<MenuItem> list; protected Context ctx; protected LayoutInflater inflater; public MenuListAdapter(Context context, List<MenuItem> objects) { this.list = objects; this.ctx = context; this.inflater = (LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(LOG_KEY, "Position: " + position + "; convertView = " + convertView + "; parent=" + parent); MenuItem item = list.get(p

Fetching a large number of contacts

I'm trying to fetch all the Phone numbers and Emails in Android.by using this code. enter code here String KEY_NAME = "Name"; String KEY_NO = "No"; String selection = ContactsContract.CommonDataKinds.Phone.IN_VISIBLE_GROUP + " = 1"; String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; String data=""; String name=""; ContactEntry contactObj; String id; List<String> temp = new ArrayList<String>(); final String[] projection = new String[]{ContactsContract.Contacts._ID , ContactsContract.Contacts.DISPLAY_NAME , ContactsContract.Contacts.HAS_PHONE_NUMBER}; final String[] email_projection = new String[] {ContactsContract.CommonDataKinds.Email.DATA , ContactsContract.CommonDataKinds.Email.TYPE}; final String[] phone_projection = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.

Fetching a large number of contacts

I'm trying to fetch all the Phone numbers and Emails in Android.by using this code. enter code here String KEY_NAME = "Name"; String KEY_NO = "No"; String selection = ContactsContract.CommonDataKinds.Phone.IN_VISIBLE_GROUP + " = 1"; String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; String data=""; String name=""; ContactEntry contactObj; String id; List<String> temp = new ArrayList<String>(); final String[] projection = new String[]{ContactsContract.Contacts._ID , ContactsContract.Contacts.DISPLAY_NAME , ContactsContract.Contacts.HAS_PHONE_NUMBER}; final String[] email_projection = new String[] {ContactsContract.CommonDataKinds.Email.DATA , ContactsContract.CommonDataKinds.Email.TYPE}; final String[] phone_projection = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.

Getting the Selected View from ListView

I am using a CursorAdapter to handle my ListActivity: public class Mclass extends ListActivity{ ... TheAdapter mAdapter; public static HashMap<Long, Boolean> shown = new HashMap<Long, Boolean>(); ... @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Boolean tmp = shown.get(id); if (tmp == null) { // if null we don't have this key in the hashmap so we added with the value true shown.put(id, true); } else { shown.put(id, !tmp.booleanValue()); // if the value exists in the map then inverse it's value } mAdapter.notifyDataSetChanged(); } } And my adapter class extends CursorAdapter and overrides bindView @Override public void bindView(View view, Context context, Cursor cursor) { String listText= cursor .getString(cursor .getColumnIndexOrThrow(DataHandler.MY_TEXT)); long id = curs

Getting the Selected View from ListView

I am using a CursorAdapter to handle my ListActivity: public class Mclass extends ListActivity{ ... TheAdapter mAdapter; public static HashMap<Long, Boolean> shown = new HashMap<Long, Boolean>(); ... @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Boolean tmp = shown.get(id); if (tmp == null) { // if null we don't have this key in the hashmap so we added with the value true shown.put(id, true); } else { shown.put(id, !tmp.booleanValue()); // if the value exists in the map then inverse it's value } mAdapter.notifyDataSetChanged(); } } And my adapter class extends CursorAdapter and overrides bindView @Override public void bindView(View view, Context context, Cursor cursor) { String listText= cursor .getString(cursor .getColumnIndexOrThrow(DataHandler.MY_TEXT)); long id = curs

Crash when switching to ListView?

I have a normal LinearLayout for my main.xml , and my second activity is a ListView . I have a button on main.xml that should take me to the ListView . I get an Unexpected Error message and have to force close when I press the button. Main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:weightSum="1" android:background="@drawable/forzabg"> <ImageView android:id="@+id/mainlogo" android:layout_width="210dp" android:layout_height="119dp" android:layout_gravity="center" android:layout_weight="0.00" android:scaleType="fitXY" android:src=&q

Edittext in Listview with wrong input onresume

I have a a listview with each row having a text field and edittext field. I have them all fight on screen. When I resume the activity by either getting a call, going back etc the input in the edittext fields does not match up with what was originally enter into. I was wondering how I could setup onresume or a saved instant state to prevent that and insure that the correct input is in the correct edittext field. This is the code I'm working with. public class editview extends ListActivity { private dbadapter mydbhelper; private PopupWindow pw; public static int editCount; public static ListView listView; public ItemAdapter adapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mydbhelper = new dbadapter(this); mydbhelper.open(); View footer = getLayoutInflater().inflate(R.layout.footer_layout, null); ListView

Stop Android SeekBar resetting

I have a ListView in which each item has a SeekBar. When I update the progress of the Seekbar this is written to a database so it can be reloaded when the application is used again. Unfortunately if the ListView is scrolled up or down so that any of the items disappear from the visible screen, when they are redrawn they are drawn with the old value. How do I get the activity to "refresh" when the SeekBar is updated so the values behind the ListView are in sync with the database, this should stop the SeekBar being redrawn with stale data. @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; try { if (view == null) { LayoutInflater vi = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = vi.inflate(R.layout.task_list_item, null); } final Task t = mList.get(position); if (t != null) { /* assign layout elements */ final SeekBar seekBar = (SeekBar