Need help: Scrolling, Refreshing custom ListDialog

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Need help: Scrolling, Refreshing custom ListDialog

Postby bones237 » Mon Jan 04, 2010 10:01 pm

Hi,
Very new to android....
Im displaying a list in a dialog that needs to be refreshed depending on certain things the user does in the app. i tried using the default ListDialog setup (as per ApiDemos sample app) and everything worked fine except the fact that when you use the .setItems feature when creating the dialog...
as so...
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.               return new AlertDialog.Builder(AlertDialogSamples.this)
  3.  
  4.                 .setTitle(R.string.select_dialog)
  5.  
  6.                 .setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() {
  7.  
  8.                     public void onClick(DialogInterface dialog, int which) {
  9.  
  10.  
  11.  
  12.                         /* User clicked so do some stuff */
  13.  
  14.                         String[] items = getResources().getStringArray(R.array.select_dialog_items);
  15.  
  16.                         new AlertDialog.Builder(AlertDialogSamples.this)
  17.  
  18.                                 .setMessage("You selected: " + which + " , " + items[which])
  19.  
  20.                                 .show();
  21.  
  22.                     }
  23.  
  24.                 })
  25.  
  26.                 .create();
  27.  
  28.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

you can't access the array you pass to refresh it if the contents of that array changed. Therefore when the list was altered (due to changes to the database), the only way to see the changes was to restart the app or activity (whichever causes onCreateDialog to be called).
To get around this i didn't use .setItems and instead set the view of the dialog to a list view created via xml and used an ArrayAdapter so that way i can refresh the list whenever i need to...
as so....
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      android:layout_width="fill_parent"
  7.  
  8.         android:layout_height="wrap_content">
  9.  
  10.    
  11.  
  12.     <ListView android:id="@+id/list2"
  13.  
  14.          android:layout_width="fill_parent"
  15.  
  16.          android:layout_height="fill_parent"/>
  17.  
  18. </LinearLayout>
  19.  
  20.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                   LayoutInflater factory3 = LayoutInflater.from(this);
  3.  
  4.                     final View textEntryView3 = factory3.inflate(R.layout.list_dialog, null);
  5.  
  6.                     mDialogFav = new AlertDialog.Builder(Favorites.this)
  7.  
  8.                         .setTitle("Which day??")
  9.  
  10.                         .setView(textEntryView3)
  11.  
  12.                     /*  
  13.  
  14.                         .setItems(names, new DialogInterface.OnClickListener() {
  15.  
  16.                             public void onClick(DialogInterface dialog, int which) {
  17.  
  18.                                         mDbHelper.insertNewFood(favName, favPt, iDs[which]);
  19.  
  20.                             }
  21.  
  22.                         })
  23.  
  24.                       */
  25.  
  26.                         .create();
  27.  
  28.                         return mDialogFav;
  29.  
  30.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


and then to set that list's contents whenever....
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                    ListView thelist =(ListView) mDialogFav.findViewById(R.id.list2);
  3.  
  4.                         thelist.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names));
  5.  
  6.                         thelist.setOnItemClickListener(new OnItemClickListener() {
  7.  
  8.  
  9.  
  10.                                 public void onItemClick(AdapterView<?> arg0, View arg1,
  11.  
  12.                                                 int arg2, long arg3) {
  13.  
  14.                                 mDbHelper.insertNewFood(favName, favPt, iDs[arg2]);
  15.  
  16.                                 mDialogFav.dismiss();
  17.  
  18.                                 }
  19.  
  20.                         });
  21.  
  22.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

This worked fine as well but now when the dialog is displayed and you touch the list to scroll it or whatever, it does this weird flashing thing in relation to your touch. The actual functionality of the whole list works fine....added a listener which works, i can refresh the dialog's list at will, etc....just this weird flashy thing..

My question..... I'd prefer to use the default ListDialog (white background) by using .setItems but how can i access the "items" i pass elsewhere in my class so i can "refresh" the items???
If there is no way and the way around it is the workaround i did already (using an xml layout) then what is up with the background of the list view flashing when its touched???.

Or.....is there a better way to do this???

Thanks in advance.....
bones237
Freshman
Freshman
 
Posts: 3
Joined: Fri Jan 01, 2010 12:54 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests