gpt4 book ai didi

Android:更改方向时出现对话框 ,"window leaked"问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:44:52 26 4
gpt4 key购买 nike

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

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

感谢任何帮助。

最佳答案

事情是你不是 dismiss() 你的 Dialog 并完成 Activity ,所以当方向改变时它会获得先前的 Dialog 状态。

因此,在您完成 Activity 之前尝试关闭 () 您的对话框。

See More Detail if any other cause :

关于Android:更改方向时出现对话框 ,"window leaked"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14622237/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com