메인엑티비티 에 4개의 프래그먼트를 만들었습니다.
첫번째 프래그먼트(가장왼쪽 프래그먼트)의 onCreateView 함수에 ProgressDialog를 넣어, 첫번째 프래그먼트가 보여질 때 로딩이 되는 것같은 다이얼로그를 잠시 띄워줍니다.
프래그먼트 생명주기대로라면 첫 번째 프래그먼트를 벗어나고 다시 첫 번째 프래그먼트로 진입하면 이 다이얼로그가 보여져야합니다.
그런데 세 번째 혹은 네 번째 프래그먼트(가장 오른쪽 프래그먼트)까지 갔다가, 두 번째 프래그먼트를 진입할 때, 이 로딩되는 것같은 다이얼로그가 생깁니다.
마치 두 번째 프래그먼트가 첫 번째 프래그먼트와 공유되는것 같습니다..
밤을새서 그런지 비몽사몽하지만 코드를 아무리 뒤져봐도 문제는 없는 것 같습니다..
//////////////////////// Fragment들이 속한 MainActivity 코드
/////////////////////////////////////////////////////////////
public class MainActivity extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
private SimpleSideDrawer mSlidingMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//위치데이터를 사용하기 위해서는 사용자로부터 permission 사용 여부를 확인 받아야 함
if ( ContextCompat.checkSelfPermission( MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions( MainActivity.this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, CONTEXT_INCLUDE_CODE );
}
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
mSlidingMenu = new SimpleSideDrawer(this); //슬라이드 메뉴 라이브러리 생성
mSlidingMenu.setLeftBehindContentView(R.layout.slide_menu);
ImageButton slide_btn = (ImageButton)findViewById(R.id.slide_btn); //슬라이드 메뉴 생성 버튼
slide_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSlidingMenu.toggleLeftDrawer();
ImageView profileImage = (ImageView)findViewById(R.id.profileImage);
TextView name = (TextView)findViewById(R.id.name);
TextView email = (TextView)findViewById(R.id.email);
Intent intent = getIntent();
String profileEmail = intent.getExtras().getString("email");
String profileName = intent.getExtras().getString("name");
Bundle b = intent.getExtras();
Bitmap bm = (Bitmap)b.get("profileImage");
profileImage.setImageBitmap(bm);
name.setText("이름 "+profileName);
email.setText("이메일 "+profileEmail);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if (position == 0)
return new Fragment1();
else if(position==1)
return new Fragment2();
else if(position==2)
return new Fragment3();
else
return new Fragment4();
}
@Override
public int getCount() {
// Show 4 total pages.
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "날씨";
case 1:
return "자연재해";
case 2:
return "범죄";
case 3:
return "설정";
}
return null;
}
}
}
프래그먼트 코드들은 문제가 없는 것 같아 해당 메인액티비티 코드를 올립니다.