在fragment
中,我创建了一个包含MapView
(MapBox)的对话框。这加载了很多。该对话框将用户(当用户点击按钮时)重定向到另一个Activity
。当用户按下Activity
(转到dialog
)时,MapView
根本不再加载,直到被按下。我正在使用MapBox's
的{{1}}实现。
我尝试通过在MapView
中调用各自的方法来实现onPause
,onResume
,onLowMemory
和onDestroy
方法,但这样MapView
1}}根本不加载,即使我点击它也不加载。
适配器的片段:
MapView
对话:
public class DayAdapter extends FragmentStatePagerAdapter {
/**
* Construct the fragment pager adapter.
* @param fragmentManager The manager
*/
public DayAdapter(final FragmentManager fragmentManager) {
super(fragmentManager);
}
/**
* Gets the Fragment to be rendered at <i>position</i>.
* @param position The position of the item.
* @return Fragment The Fragment that has to be rendered.
*/
@Override
public Fragment getItem(int position) {
Fragment fragment = new DayFragment();
Bundle args = new Bundle();
args.putInt(DayFragment.ARG_OBJECT, position);
fragment.setArguments(args);
return fragment;
}
/**
* Gets the total count of items.
* @return Integer The amount of items.
*/
@Override
public int getCount() {
return 100;
}
/**
* Fragment to display the Day.
*/
public static class DayFragment extends Fragment {
public static final String ARG_OBJECT = "object";
private final Client client = Client.getInstance();
private WorkorderDialog d;
/**
* Constructs the Day view.
* @param inflater The inflater for the Fragment.
* @param container The container of the Fragment.
* @param savedInstanceState The arguments of the saved state.
* @return View The view of the day.
*/
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container, final Bundle savedInstanceState) {
final View rootView = inflater.inflate(
R.layout.day_fragment, container, false);
final Bundle args = getArguments();
final int dayPosition = args.getInt(ARG_OBJECT);
final int deviation = dayPosition - 50;
final Date devDate = DateUtil.getDateFromNow(deviation);
final String renderedDate = DateUtil.getDayInWeek(devDate) + " "
+ DateUtil.getDayOfMonth(devDate) + " "
+ DateUtil.getMonth(devDate);
((TextView) rootView.findViewById(R.id.date)).setText(renderedDate);
final String currentDate = new SimpleDateFormat("MM/dd/yyyy").format(devDate);
final JSONArray workOrders = client.getWorkOrders(currentDate);
final ListView jobList = (ListView) rootView.findViewById(R.id.jobList);
jobList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
d = new WorkorderDialog(client.getCurrentActivity(), workOrders.getJSONObject(i), renderedDate, savedInstanceState);
d.constructDialog();
d.show();
} catch (JSONException e) {
Log.e("CrafterException", e.getMessage());
}
}
});
jobList.setEmptyView(rootView.findViewById(R.id.emptyTextView));
jobList.setAdapter(new JobAdapter(workOrders, inflater));
return rootView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (d != null) {
d.onResume();
}
}
@Override
public void onResume() {
super.onResume();
if (d != null) {
d.onResume();
}
}
@Override
public void onPause() {
super.onPause();
if (d != null) {
d.onPause();
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
if (d != null) {
d.onLowMemory();
}
}
}
答案 0 :(得分:1)
在Fragment
的{{1}}实施中,您需要在MapView
中致电MapView#onDestroy
,如下所示:
Fragement#onDestroyView
这可确保@Override
public void onDestroyView() {
super.onDestroyView();
mapView.onDestroy();
}
正确关闭,以便在第二次显示对话框时再次使用它。希望这有帮助!