接口从后preSS回到应用程序后,没有重新加载 [英] Interface not reloaded after returning to app from BACK press

查看:136
本文介绍了接口从后preSS回到应用程序后,没有重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一组选项卡,每个连接到一个片段,而我终于得到了用户界面上的选项卡中的一个来看看应该如何。这里有一个如何在应用程序的外观时,它已经正确加载截图(首次推出后,并滚动到一个标签):现在,当我打的后退按钮(我没有,也不会与一个backStack困扰每个标签 - 我不喜欢这样的UI模式),然后使用应用程序切换器或重新启动从启动,我questionRows都走了(他们不重装)。我需要实现的东西的onPause救我的显示器?为什么不onResume把它的这种关心?

 包com.davekelley.polling;

进口android.app.Activity;
进口android.app.AlertDialog;
进口android.content.Context;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.view.View.OnClickListener;
进口android.view.ViewGroup.LayoutParams;
进口android.view.inputmethod.InputMethodManager;
进口android.widget.Button;
进口android.widget.LinearLayout;
进口android.widget.RelativeLayout;
进口android.widget.ScrollView;
进口android.widget.TableLayout;
进口android.widget.TableRow;
进口android.widget.TextView;
进口android.support.v4.app.Fragment;

公共类EconFragment扩展片段{

    私人的ViewGroup容器;
    私人TableLayout questionContainer;
    私人滚动型滚动视图;
    私人的ViewGroup econFragment;
    静态INT POS = 0;

    公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
        Log.d(经济舱,onCreateView);
        this.container =容器;
        返回inflater.inflate(R.layout.econfragment,集装箱,假);
    }

    公共无效onResume(){
        super.onResume();
        questionContainer =(TableLayout)getActivity()findViewById(R.id.questionContainer)。

        LayoutInflater充气=(LayoutInflater)getActivity()。
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        //这行是我第一次尝试,试图得到返回后重新填充的问题
        //从pressing回来 - 作为然而,他们没有重新填充屏幕:
        //查看econFragment = inflater.inflate(R.layout.econfragment,NULL);
        //container.addView(econFragment);

        INT LEFTMARGIN = 5;
        INT TOPMARGIN = 5;
        INT rightMargin = 5;
        INT bottomMargin = 5;
        而(正小于10){
        查看问题= inflater.inflate(R.layout.question,NULL);
        question.setId(POS);
        POS ++;
        的TableRow TR =(的TableRow)的问题;
        TableLayout.LayoutParams trParams =新TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.WRAP_CONTENT);
        trParams.setMargins(LEFTMARGIN,TOPMARGIN,rightMargin,bottomMargin);
        tr.setLayoutParams(trParams);
        questionContainer.addView(TR);
        }
        Log.d(经济舱,onResume);
    }

    公共无效onAttach(活动活动){
        super.onAttach(活动);
        Log.d(经济舱,onAttach);
    }

    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        Log.d(经济舱,的onCreate);

    }

    公共无效onActivityCreated(包savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        Log.d(经济舱,onActivityCreated);
    }

    公共无效的OnStart(){
        super.onStart();
        Log.d(经济舱,的OnStart);
    }

    公共无效的onPause(){
        super.onPause();
        Log.d(经济舱,的onPause);
    }

    公共无效的onStop(){
        super.onStop();
        Log.d(经济舱,的onStop);
    }

    公共无效onDestroyView(){
        super.onDestroyView();
        Log.d(经济舱,ondestroyview);
    }

    公共无效的onDestroy(){
        super.onDestroy();
        Log.d(经济舱,的OnDestroy);

    }

    公共无效onDetach(){
        super.onDetach();
        Log.d(经济舱,ondetach);
    }
}
 

解决方案

还挺得到了提上了次要地位,因为我曾在我的应用程序的其他方面的问题。原来的解决方案是一个简单的:如在code所列POS变量是静态的,所以while循环无法从0-10 reclimb。这里的答案:<一href="http://stackoverflow.com/questions/9960035/even-though-oncreateview-runs-again-view-does-not-properly-reassemble-after-bac/9960160#9960160">Even虽然onCreateView再次运行,显示不正常后返回preSS重组?

I currently have a set of tabs, each tied to a fragment, and I've finally gotten the UI on one of the tabs to look how it should. Here's a screenshot of how the app looks when it has properly loaded (after initial launch and scrolling to a tab): Now, after I hit the back button (I haven't and won't be bothering with a backStack for each tab - I don't like that UI paradigm) and then use app switcher or relaunch from the launcher, my questionRows are gone (they don't reload). Do I need to implement something in onPause to save my display? Why doesn't onResume take care of it this?

package com.davekelley.polling;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.support.v4.app.Fragment;

public class EconFragment extends Fragment {

    private ViewGroup container;
    private TableLayout questionContainer;
    private ScrollView scrollView;
    private ViewGroup econFragment;
    static int pos = 0;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d("Econ", "onCreateView");
        this.container = container;
        return inflater.inflate(R.layout.econfragment, container, false);
    }

    public void onResume() {
        super.onResume();
        questionContainer = (TableLayout) getActivity().findViewById(R.id.questionContainer);

        LayoutInflater inflater = (LayoutInflater) getActivity().
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        //these lines are my first attempt to try and get the questions to repopulate after returning
        //from pressing back - as of yet, they don't repopulate the screen:
        //View econFragment = inflater.inflate(R.layout.econfragment, null);
        //container.addView(econFragment);

        int leftMargin=5;
        int topMargin=5;
        int rightMargin=5;
        int bottomMargin=5;
        while (pos < 10) {
        View question = inflater.inflate(R.layout.question, null);
        question.setId(pos);
        pos++;
        TableRow tr = (TableRow) question;
        TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.WRAP_CONTENT);
        trParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
        tr.setLayoutParams(trParams);
        questionContainer.addView(tr);
        }
        Log.d("Econ", "onResume");
    }

    public void onAttach(Activity activity) {
        super.onAttach(activity);
        Log.d("Econ", "onAttach");
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("Econ", "onCreate");

    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d("Econ", "onActivityCreated");
    }

    public void onStart() {
        super.onStart();
        Log.d("Econ", "OnStart");
    }

    public void onPause() {
        super.onPause();    
        Log.d("Econ", "onpause");
    }

    public void onStop() {
        super.onStop();
        Log.d("Econ", "onstop");
    }

    public void onDestroyView() {
        super.onDestroyView();
        Log.d("Econ", "ondestroyview");
    }

    public void onDestroy() {
        super.onDestroy();
        Log.d("Econ", "ondestroy");

    }

    public void onDetach() {
        super.onDetach();
        Log.d("Econ", "ondetach");
    }
}

解决方案

The question kinda got put on the backburner as I worked on other areas of my app. It turns out the solution was a simple one: the pos variable as listed in the code was static, so the while loop could not reclimb from 0-10. Here's the answer: Even though onCreateView runs again, View does not properly reassemble after BACK press?

这篇关于接口从后preSS回到应用程序后,没有重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆