views:

146

answers:

1

Hi there,

I am trying to set up a ViewFlipper that changes a SlidingDrawers content each time a button is pressed. So far every view I set up worked fine, but now I am trying to create a ListView (including single_choice_mode) within a child view of the ViewFlipper, but my attempt only let to a NullPointerException. As I only discovered ViewFlipper today, I am not yet familiar with it and may not have understood it completely...if someone could give me a hand and help me find out what I have done wrong, that would be great.

Thank you in advance.


Here is what I have done:

The code for the onClick event of the ImageButtons:

    public void onClick(View v){
   if (v == btnExposure){

    mFlipper.setDisplayedChild(0);

   }
   else if (v == btnProperties){
    mFlipper.setDisplayedChild(1);
   }

   else if (v == btnSpecialEffects){
    mFlipper.setDisplayedChild(2);
    String[] specialEffects = getResources().getStringArray(R.array.special_effects_array);
          lv.setAdapter(new ArrayAdapter<String>(this, R.layout.specialeffectsview, specialEffects));
          lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
   }

  }

The XML code of the ViewFlipper within my main xml file:

<ViewFlipper
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content"
   android:id="@+id/flipper"
   android:layout_toRightOf="@id/button_exposure">
   <include android:id="@+id/view_exposure" layout="@layout/exposureview" />
   <include android:id="@+id/view_properties" layout="@layout/propertiesview" />
   <include android:id="@+id/view_special_effects" layout="@layout/specialeffectsview"/>
  </ViewFlipper>

The string array within my strings.xml:

<string-array name="special_effects_array">
        <item>None</item>
        <item>Greyscale</item>
        <item>Sepia</item>
        <item>Negative</item>
        <item>Solarize</item>
        <item>Polarize</item>
    </string-array>

And finally the specialeffectsview.xml (the layout file for the ListView):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/view_special_effects_list"
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<ListView android:id="@+id/special_effects_list" 
 android:layout_height="wrap_content"
 android:layout_width="fill_parent"></ListView>
</LinearLayout>
A: 

As has been discussed on the Android Google Groups when you inquired there, your NullPointerException is because your lv variable is null. You need to make that be not null, probably by calling lv=(ListView)findViewById(R.id.special_effects_list) at some point after setContentView().

CommonsWare
I already tried that but as that also didn't work I changed the layout to a simple LinearLayout with a RadioButton Group, not my ideal and final solution, but for now that should do the trick...
kivy