调用自身内部的片段

时间:2019-01-29 06:19:43

标签: android android-fragments

我面临着无法在片段Ui上显示实时数据的问题,我注意到,每当再次调用该片段Ui都会更新。这是片段Ui的一些图片。

https://unsee.cc/99e332df/

当我单击oni Ui更新时;

片段代码:

public class SpeedFragment extends Fragment {

    View view;
    TextView SpeedFrgvalue;
    DigitSpeedView DigitrpmFrgView;
    SpeedView speedometer;

    Button DigitalView,Gaugeview;
    LinearLayout linearLayoutspeed;


    public SpeedFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_speed, container, false);
        SpeedFrgvalue=(TextView)view.findViewById(R.id.speedfrgvalue);
        speedometer=(SpeedView)view.findViewById(R.id.speedViewfrag);
        Gaugeview=(Button)view.findViewById(R.id.Gaugeviewid);
        DigitalView=(Button)view.findViewById(R.id.digitalviewid);

        linearLayoutspeed=(LinearLayout)view.findViewById(R.id.digitalspeedlinaear);
        Bundle bundle = this.getArguments();
        String mySpeed = bundle.getString("speed");

        SpeedFrgvalue.setText(mySpeed);

        DigitrpmFrgView=(DigitSpeedView)view.findViewById(R.id.digitalSpeedfrgid);
        DigitrpmFrgView.updateSpeed(Integer.valueOf(mySpeed));

        speedometer.setMaxSpeed(250);

        speedometer.speedTo(Integer.valueOf(mySpeed),4000);

//        speedometer.speedPercentTo(100, 5000);



        return view;

    }
}

按钮点击代码:

public void onClick(View v) {

 vv.setVisibility(View.GONE);
                Framelauoutcontainer.setVisibility(View.VISIBLE);


                SpeedFragment speedFragment;
                speedFragment = new SpeedFragment();
                speedFragment.setArguments(Sbundle);


                RoboActivity activity = MainActivity.this;
                if (!isFinishing() && !isDestroyed()) {

                    FragmentTransaction ft = activity.getFragmentManager()
                            .beginTransaction();
                    ft.replace(R.id.fragment_container, speedFragment);
                    ft.commit();
                }



}

我想更新ui,除Fragment调用外,其他任何方式都欢迎

0 个答案:

没有答案