안녕하세요. 제 질문은 이쪽입니다. 나는 탭이있을 때 밑 부분 시트가 안에 다른 조각으로 열리는 버튼이있는 View Pager 안에 조각을 가지고 있습니다. 맨 아래 시트에는 객체 목록이 있으며, 사용자가 내가 앞서 언급 한 첫 번째 조각에 객체를 전달하기를 원할 때 그 단편이 일시 중지되었다는 것이 문제입니다. 한 조각에서 다른 조각으로 일시 중지 된 데이터를 보내려면 어떻게해야합니까?단편 및 단편 통신
1
A
답변
0
조각간에 데이터를 전달하는 방법은 여러 가지가 있습니다. 몇몇은 다음과 같습니다
가- 당신은 당신은 조각이나 활동 간에 데이터를/업데이트 전달하는 인터페이스를 사용할 수 있습니다 당신은 자신의 부모 활동
- 를 사용하여 조각 사이에서 데이터를 공유 할 수 있습니다 조각 클래스
- 참여의 게터/세터를 사용할 수 있습니다
- 당신은 또한 데이터
당신의 필요에 가장 잘 맞는 방식을 선택하는 것은 당신에게 달려 있습니다.
0
사용이
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
System.out.print(position + "to" + tab_position);
Fragment fragment = null;
switch (position) {
case 0:
Bundle bundle = new Bundle();
bundle.putString("message", "getdata");
bundle.putStringArrayList("name", running_veicle);
bundle.putStringArrayList("loc", running_loc);
bundle.putStringArrayList("running_device_id", running_device_id);
fragment = new Vehicle_Status_fragment_running_info();
fragment.setArguments(bundle);
break;
case 1:
Bundle bundle1 = new Bundle();
bundle1.putString("message", "getdata");
bundle1.putStringArrayList("name", idle_name);
bundle1.putStringArrayList("loc", idle_loc);
bundle1.putStringArrayList("idle_device_id", idle_device_id);
fragment = new Vehicle_Status_fragment_Idle_info();
fragment.setArguments(bundle1);
break;
case 2:
Bundle bundle2 = new Bundle();
bundle2.putString("message", "getdata");
bundle2.putStringArrayList("name", stop_name);
bundle2.putStringArrayList("loc", stop_loc);
bundle2.putStringArrayList("stop_device_id", stop_device_id);
fragment = new Vehicle_Status_fragment_Stop_info();
fragment.setArguments(bundle2);
break;
case 3:
Bundle bundle3 = new Bundle();
bundle3.putString("message", "getdata");
bundle3.putStringArrayList("name", Innactive_name);
bundle3.putStringArrayList("loc", Innactive_loc);
bundle3.putStringArrayList("innactive_device_id", Innactive_device_id);
fragment = new Vehicle_Status_fragment_Inactive_info();
fragment.setArguments(bundle3);
break;
}
return fragment;
}
@Override
public int getCount() {
// Show 4 total pages.
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.tab_Running).toUpperCase(l);
case 1:
return getString(R.string.tab_Idle).toUpperCase(l);
case 2:
return getString(R.string.tab_Stop).toUpperCase(l);
case 3:
return getString(R.string.tab_Innactive).toUpperCase(l);
}
return null;
}
}
데이터
View view = inflater.inflate(R.layout.fragment_tab_veicle_status_list, container, false);
listobj = (ListView) view.findViewById(R.id.gridview);
String myValue = this.getArguments().getString("message");
+0
조각이 정보를 onPause()에 전달하고 싶습니까? 그 조각을 다시 만들지는 마 – Andrea
확인 조각 라이프 사이클을 얻을. – Piyush
지금까지 피곤했던 것은 무엇입니까? – Wizard
@Andrea Fragment는 활동이 일시 정지 상태 인 경우 일시 중지됩니다. –