0
나는 밑줄 라이브러리를 사용하여 응용 프로그램을 만듭니다. 나는 'com.roughike을 : 하단 바 : 2.0.2'다른 프래그먼트를 열 때 프래그먼트를 고정하는 방법
컴파일을 사용하고
나는이
public class EventFragment extends Fragment {
private RecyclerView rcEvent;
private EventAdapter mAdapter;
private List<EventModel> mgridData;
private LinearLayoutManager layoutManager;
private SwipeRefreshLayout mSwipe;
public EventFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView= inflater.inflate(R.layout.fragment_event, container, false);
mSwipe= (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefresh);
rcEvent = (RecyclerView) rootView.findViewById(R.id.rv);
layoutManager = new LinearLayoutManager(getActivity());
rcEvent.setLayoutManager(layoutManager);
mgridData = new ArrayList<>();
mAdapter = new EventAdapter(getActivity(), mgridData);
rcEvent.setAdapter(mAdapter);
fetchData();
mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
fetchData();
//mSwipe.setRefreshing(false);
}
});
return rootView;
}
public void fetchData()
{
mSwipe.setRefreshing(true);
apiData api= ApiClient.getClient().create(apiData.class);
Call<EventResponse> call=api.GetEvent();
call.enqueue(new Callback<EventResponse>() {
@Override
public void onResponse(Call<EventResponse> call, Response<EventResponse> response) {
if(response.isSuccessful())
{
EventResponse result=response.body();
Log.d("Event", "response = " + new Gson().toJson(result));
if(result !=null)
{
List<EventModel> eventResponse= result.getEventData();
if(eventResponse !=null)
{
for (EventModel eventRespon :eventResponse) {
mgridData.add(eventRespon);
}
RecyclerView.Adapter adapter = new EventAdapter(getActivity(), mgridData);
mAdapter.setListData(mgridData);
rcEvent.setAdapter(adapter);
}
mSwipe.setRefreshing(false);
}
}
}
@Override
public void onFailure(Call<EventResponse> call, Throwable t) {
Toast.makeText((MainActivity)getActivity(), "Koneksi Ke Internet Gagal", Toast.LENGTH_SHORT).show();
mSwipe.setRefreshing(false);
}
});
}
}
MainActivity 추천 조각을 HVE. Java
public class MainActivity extends AppCompatActivity {
boolean doubleBackToExitPressedOnce = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Declare Fragment
final EventFragment eventFragment=new EventFragment();
final BloodFragment bloodFragment=new BloodFragment();
final MerchantFragment merchantFragment=new MerchantFragment();
final StoreFragment storeFragment=new StoreFragment();
final ProfileFragment profileFragment=new ProfileFragment();
BottomBar bottomBar=(BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
if (tabId == R.id.tab_event) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentContainer, eventFragment, eventFragment.getClass().getName())
.commit();
}
else if(tabId == R.id.tab_blood){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentContainer, bloodFragment, bloodFragment.getClass().getName())
.commit();
}
else if(tabId == R.id.tab_merchant){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentContainer, merchantFragment, merchantFragment.getClass().getName())
.commit();
}
else if(tabId == R.id.tab_store){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentContainer, storeFragment, storeFragment.getClass().getName())
.commit();
}
else if(tabId == R.id.tab_profile){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentContainer, profileFragment, profileFragment.getClass().getName())
.commit();
}
}
});
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
finish();
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please press BACK again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce=false;
}
}, 2000);
}
}
내 문제는 첫 번째 조각로드가 완료되기 전에 다른 조각을 열면 오류가 발생합니다. 프로세스가 완료되면 다른 부분에 있기 때문에 오류가 발생했습니다. 그래서 다른 프래그먼트를 열었을 때 프래그먼트를 고정시키고 프래그먼트를 다시 열었을 때 프 로젝트를 재개하려고합니다. 내 코드에서 구현하는 데 문제가 있습니다. 도와주세요. 고맙습니다.
내가 거기에 무엇을 작성해야합니다 :
당신이 사용할 수있는 조각의 상태를 저장하려면? 미안해, 초보자 야. 그래서 나는 더 많은 설명이 필요하다. 어떤 종류의 코드 조각을 저장하고 조각을 복원하는 데 사용해야합니까? –여기에서 볼 수 있습니다 : http://stackoverflow.com/questions/22505327/android-save-restore-fragment-state 도움이 되셨습니까? –