조각 기반 앱을 개발했습니다.조각이로드되는 동안 로딩 스피너 표시
단추가있는 메뉴 조각이 있는데,이 단추는 각 조각을 하나씩 열고 마지막 조각을 대체합니다.
문제는 일부 조각이 asynctasks에 대한 호출을 수행하고 일부 listviews를 채우는 원인으로 인해 약간의 시간이 소요된다는 것입니다.
그래서 메뉴 조각에서 단추를 누르면 메뉴 조각을 대체 할 새 조각이 나타날 때까지 2 초 동안 고정되어 있습니다.
그 당시 회 전자 또는 "로드 중 ..."대화 상자가 나타납니다.
이 나는이
private progressDialog progressDialog;
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.show();
이 코드는 대화 상자를 보여 테스트하지만, 화면이 얼어 붙었다 때 그것은 결코 그것을 보여줍니다 없다.
어디에서 코드를 삽입해야합니까? 모든 단편이나 메뉴 단편을 포함하는 활동에서? 또는로드 된 조각에있을 수 있습니까?
내 메뉴 조각에서 다음 코드를 수행 할 때 버튼을 누르면이 작업을 수행하지 않아도됩니다.
NewAppointmentFragment fragment = new NewAppointmentFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
"NewAppointmentFragment");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
하지만이 새로운 조각이로드되고 버튼과 메뉴 단편 내가 모든 전화 새로운 조각의 원인이 될 수
를 누르면 볼 수 있습니다 얼어 붙었다 2 초 나타날 때까지 2 초 정도 걸립니다 OnCreateView에서 listviews를 채우기위한 asynctasks 및 작업?
어떻게이 문제를 해결할 수 있습니까?사전에
감사
내 메뉴 단편
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
nextAppointmentsButton = (Button)
rootView.findViewById(R.id.nextAppointmentsButton);
nuevaCitaButton = (Button) rootView.findViewById(R.id.nuevaCitaButton);
nearbyPharmaciesButton = (Button)
rootView.findViewById(R.id.nearbyPharmaciesButton);
ourLocationButton = (Button) rootView.findViewById(R.id.ourLocationButton);
nextAppointmentsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UpcomingAppointmentsFragment fragment = new
UpcomingAppointmentsFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
nuevaCitaButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((MainActivity)getActivity()).showProgressDialog();
NewAppointmentFragment fragment = new NewAppointmentFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
"NewAppointmentFragment");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
nearbyPharmaciesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NearbyPharmaciesFragment fragment = new NearbyPharmaciesFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
ourLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OurLocationMapFragment fragment = new OurLocationMapFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
// Inflate the layout for this fragment
return rootView;
}
내가
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_new_appointment,
container, false);
// **Calls to asynctasks **
// **Populate operations ListViews**
return rootView;
}
'ProgressDialog'는 공식적으로 안드로이드 팀에 의해 평가되었습니다. 액티비티 내에서'ProgressBar' (또는 비슷한 것) 구현이 이제 권장됩니다. – anthony