0

我必须为姜饼版本实现多选对话框。

我的名为 EventCreateActivity 的主要活动扩展了名为 BaseActivity 的类,并扩展了 SherlockActivity。

主要活动

public class EventCreateActivity extends BaseActivity implements OfferDialogFragment.OfferDialogListner{ 

在主要活动中,我如下调用对话框,但它在 newFragment.show 方法上给出错误,称为“方法 getSupportFragmentManager() 未定义类型 EventCreateActivity”。OfferDialogFragment 类扩展了 dialogFragment 类。

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");

如果有人帮我解决这个问题,那将是非常高兴的。提前致谢!

编辑 01:这里是 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 类

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();
}

}

4

1 回答 1

0

getSupportFragmentManager中不存在SherlockActivity-您想getFragmentManager改用。

于 2013-09-26T10:33:42.817 回答