6

我有两个类,一个适配器和一个活动,我有一个在适配器中显示的 dailog。当我尝试更改屏幕方向时出现错误。我尝试在我的活动中覆盖以下代码。但似乎没有任何效果

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
          Log.d(TAG, "configuration changed : " +newConfig);

    }

下面是我的适配器代码

public AddressPopUpAdapter(Activity activity, Activity parent,
            int resourceId, ArrayList<PopUpMenu> items, int renderer) {
        super(activity, resourceId, items);
        this.items = items;
        this.renderer = renderer;
        this.activity = activity;
        this.parentActivity = parent;
        popupMenuUtils = new PopupMenuUtils();
        dialog = new Dialog(parentActivity);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        popUpMenu = items.get(position);
        Log.d(TAG, "location" + popUpMenu);
        if (popUpMenu == null) {
            return null;
        }
        Log.d(TAG, "location" + popUpMenu);
        View view = convertView;
        if (view == null) {
            LayoutInflater layoutInflater = (LayoutInflater) (getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE));
            view = layoutInflater.inflate(renderer, null);

        }

        final LinearLayout popupmain = (LinearLayout) view
                .findViewById(R.id.popupmain);

        popupmain.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setEnabled(false);
                performAction(v, activity);

            }
        });

        if (position % 2 == 0) {

            view.setBackgroundResource(R.drawable.listshape);

        } else {
            view.setBackgroundResource(R.drawable.favoritebody);
        }
        return view;
    }

    public void performAction(View v, Activity activity) {

        Context myContext = v.getContext();
        PopUpMenu popUpMenu = (PopUpMenu) v.getTag();
        String result = popUpMenu.getMenuName();
        if (result != null
                && result.equalsIgnoreCase(myContext.getResources().getString(
                        R.string.savecurrentlocation))) {
            getCurrentLocation();

        }

        else if (result != null
                && result.equalsIgnoreCase(myContext.getResources().getString(
                        R.string.distancebetween))) {
            AttractionService service = AttractionService
                    .getInstance(parentActivity.getApplicationContext());
            ArrayList<AttractionData> allMenuSearchList = service
                    .getAllAttractions(true, Constants.field, Constants.order);

            if (allMenuSearchList != null && !allMenuSearchList.isEmpty()) {

                dialog.setContentView(R.layout.pickdestination);
                ListView listPlace = (ListView) dialog
                        .findViewById(R.id.listPlace);
                PlaceAdapter placeAdapter = new PlaceAdapter(parentActivity,
                        allMenuSearchList, R.layout.pickcity, dialog,
                        R.string.pickstartingpoint, null);
                listPlace.setAdapter(placeAdapter);
giving error here----------->   dialog.show();

            } else {
                Toast.makeText(parentActivity, R.string.nonavigationtolink,
                        Toast.LENGTH_SHORT).show();

            }

            this.activity.finish();
        }

任何帮助表示赞赏。

4

3 回答 3

3

问题是您没有解除()您的对话框并完成活动,因此当方向更改时,它将获得先前的对话框状态。

所以try to dismiss() your dialog before you finish your activity.

如果有任何其他原因,请查看更多详细信息:

于 2013-01-31T09:32:22.727 回答
2

根据 chintan/Stephan 的上述提示;我将 AlertDialog 引用设为 Activity 的全局,并在 onDestroy() 中关闭:

if (ad!=null) {
 ad.dismiss();
 ad=null;
}

轮换时不再记录泄漏错误。

我不想考虑那些 configChanges 参数,因为如果您已经有横向或类似的特定布局,它们会搞砸。

于 2013-07-30T16:01:17.297 回答
-3

此问题的解决方法是添加

android:configChanges="orientation"

您在清单中的活动。

于 2013-01-31T09:36:18.927 回答