0

I have to implement multiple select dialog box for gingerbread version.

My main Activity called EventCreateActivity extends class called BaseActivity and that extends SherlockActivity.

main activity

public class EventCreateActivity extends BaseActivity implements OfferDialogFragment.OfferDialogListner{ 

within main activity i called for dialog as follows, but it gives an error on newFragment.show method called "The method getSupportFragmentManager() is undefined for the type EventCreateActivity". OfferDialogFragment class has extends dialogFragment class.

DialogFragment newFragment = new OfferDialogFragment();     
Bundle databndle = new Bundle();
boolean offerArr [] = vip.getBooleanOffers(include_offer.getText().toString());
databndle.putBooleanArray("BOOL_OFFERS_ARRAY", offerArr);
newFragment.setArguments(databndle);                        
newFragment.show(getSupportFragmentManager(), "OfferDialogFragment");

it would be grate if anyone give me a help to solve this. thanks in advance!

Edit 01: here is entire code of EventCreateActivity

public class EventCreateActivity extends BaseActivity implements  OfferDialogFragment.OfferDialogListner{

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
       // set date picker as current date
       return new DatePickerDialog(this, datePickerListener, 
                     year, month,day);         
    case OFFER_DIALOG_ID: 

        DialogFragment newFragment = new OfferDialogFragment();

        Bundle databndle = new Bundle();
        boolean offerArr [] = vip.getBooleanOffers(include_offer.getText().toString());
        databndle.putBooleanArray("BOOL_OFFERS_ARRAY", offerArr);
        newFragment.setArguments(databndle);            

        newFragment.show(getFragmentManager(), "OfferDialogFragment");

        return onCreateDialog(id);
    }

}

// OfferDialogFragment Class

public class OfferDialogFragment extends SherlockDialogFragment{

public interface OfferDialogListner{
    public void onDialogPositiveClick(DialogFragment dialog, ArrayList<Integer> selected);
    public void onDialogNegativeClick(DialogFragment dialog);
}

OfferDialogListner mOfferDialogListner;

@Override
public void onAttach(android.app.Activity activity) {
    super.onAttach(activity);

    try{
        mOfferDialogListner = (OfferDialogListner) activity;
    }catch(ClassCastException e){
        throw new ClassCastException(activity.toString() + " must implement OfferDialogListner");
    }
};

@Override   
public Dialog onCreateDialog(Bundle savedInstanceState){

    final ArrayList<Integer> mSelectedOfferItems = new ArrayList<Integer>();        

    boolean [] selectOfferItems = getArguments().getBooleanArray("BOOL_OFFERS_ARRAY");
        // add array data to arrayalist
    if(selectOfferItems[0]){                
        mSelectedOfferItems.add(0);
    }
    if(selectOfferItems[1]){                
        mSelectedOfferItems.add(1);
    }
    if(selectOfferItems[2]){                
        mSelectedOfferItems.add(2);
    }           
    if(selectOfferItems[3]){                
        mSelectedOfferItems.add(3);
    }   

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle(R.string.artist_offer_tv)
            .setMultiChoiceItems(R.array.offer_items, selectOfferItems, new DialogInterface.OnMultiChoiceClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {

                    if(isChecked){
                        mSelectedOfferItems.add(which);                         

                    }else{
                        mSelectedOfferItems.remove(Integer.valueOf(which));
                    }

                }
            })
            .setPositiveButton(R.string.string_ok , new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Integer[] selected = mSelectedOfferItems.toArray(new Integer[mSelectedOfferItems.size()]);


                               mOfferDialogListner.onDialogPositiveClick(OfferDialogFragment.this, mSelectedOfferItems);
                }
            })

            .setNegativeButton(R.string.string_cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    mOfferDialogListner.onDialogNegativeClick(OfferDialogFragment.this);
                }
            });

    return builder.create();
}

}

cham
  • 43
  • 11

1 Answers1

0

getSupportFragmentManager doesn't exist in SherlockActivity - you want to use getFragmentManager instead.

Dave
  • 6,064
  • 4
  • 31
  • 38
  • hi Dave, yes. then error says "The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentManager, String)" – cham Sep 26 '13 at 10:38
  • Is your dialog extending from `SherlockDialogFragment`? – Dave Sep 26 '13 at 10:39
  • no. it extends DialogFragment, even though changed to SherlockDialogFragment, error is stil there. it says "The method getSupportFragmentManager() is undefined for the type EventCreateActivity" – cham Sep 26 '13 at 10:45
  • Whoops, yes - since you're using fragments, your Activity should extend from `SherlockFragmentActivity` then! (been a while since I used Sherlock) – Dave Sep 26 '13 at 10:52
  • Not any success yet. I will put whole code, some time it will help u guy to solve this. – cham Sep 26 '13 at 10:59
  • Finally i found you are right! "your Activity should extend from SherlockFragmentActivity then!" – cham Sep 27 '13 at 06:29