Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 调用片段方法?_Java_Android_Android Fragments_Methods - Fatal编程技术网

Java 调用片段方法?

Java 调用片段方法?,java,android,android-fragments,methods,Java,Android,Android Fragments,Methods,我把这个密码输入到残害中了 public void CargarFragment(View view){ //esto solo si es llamado desde el click de un boton Bundle arguments = new Bundle(); RelativeLayout fragm_v = (RelativeLayout) findViewById(R.id.estoSeCambiara); //get the layout from sh

我把这个密码输入到残害中了

public void CargarFragment(View view){ //esto solo si es llamado desde el click de un boton

    Bundle arguments = new Bundle();

    RelativeLayout fragm_v = (RelativeLayout) findViewById(R.id.estoSeCambiara); //get the layout from show the fragment

    LayoutInflater inflater = LayoutInflater.from(this); //create the inflater

    View v;

    v = inflater.inflate(R.layout.fragment_blank_fragment_pruebas_lllamada_method, fragm_v, true); //the fragment apear

}
在片段中:

    package com.sociosinversores.www.fragmentstatico;

import android.app.Activity; //import this thing
import android.net.Uri;//import this thing
import android.os.Bundle;//import this thing
import android.app.Fragment;//import this thing
import android.view.LayoutInflater;//import this thing
import android.view.View;//import this thing
import android.view.ViewGroup;//import this thing
import android.widget.TextView;//import this thing
import android.widget.Toast; //load the imports


public class BlankFragment_pruebasLllamadaMethod extends Fragment { //start the class
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1"; //generate this thing
    private static final String ARG_PARAM2 = "param2";//generate this thing

    View view; //the viewroot

    // TODO: Rename and change types of parameters
    private String mParam1; //add the parameters
    private String mParam2; //add the parameters

    private OnFragmentInteractionListener mListener; //declarate the listener


    // TODO: Rename and change types and number of parameters
    public static BlankFragment_pruebasLllamadaMethod newInstance(String param1, String param2) { //autogenerated
        BlankFragment_pruebasLllamadaMethod fragment = new BlankFragment_pruebasLllamadaMethod();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1); //autogenerated
        args.putString(ARG_PARAM2, param2); //autogerated
        fragment.setArguments(args);
        return fragment; //return the fragment
    }

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

    @Override
    public void onCreate(Bundle savedInstanceState) { //autogenerated
        super.onCreate(savedInstanceState); //autogenerated
        if (getArguments() != null) { //¿?¿?¿?¿?¿?¿?¿?¿?
            mParam1 = getArguments().getString(ARG_PARAM1); //autogenerated 
            mParam2 = getArguments().getString(ARG_PARAM2); //autogenerated
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //add the fragment to the mainactivity

        view = inflater.inflate(R.layout.fragment_blank_fragment_pruebas_lllamada_method,container);

        sustituir(); //i try to call the method

        return view; //return the view
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) { //autogenerated
        if (mListener != null) {
            mListener.onFragmentInteraction(uri); //???????
        }
    }



    @Override
    public void onAttach(Activity activity) { //auto generated by the fragment
        super.onAttach(activity); //call to the super (activity)
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    public void sustituir(){ //the class that i want call

        TextView t = (TextView) view.findViewById(R.id.rtyui); //call to the textview 
        t.setText("Funciono"); //set text

        Toast.makeText(getActivity(),"Entra!",Toast.LENGTH_SHORT).show(); //a toast to view what happens

    }

    @Override
    public void onDetach() { //autogenerated
        super.onDetach(); /¿?
        mListener = null; //¿?
    }

    public interface OnFragmentInteractionListener { //auto generated 
        // TODO: Update argument type and name
        public void onFragmentInteraction(Uri uri); //i don't know that do this

    }

}
创建操作时,如何调用方法“sustituir()”

我想知道如何调用该方法,因为在我的实际项目中,我进行了DB远程调用。我想先控制我的项目


有什么想法吗?

当你想调用方法时,以及在活动和其他活动中的何处?哦,哦,你会怎么做?一点代码会有点帮助,我有点迷茫。你想调用方法的动作是什么???加载片段后,我想调用方法。当你想调用方法时,以及在活动和其他活动中的何处?哦,哦,你会怎么做?一点代码会有点帮助,我有点迷茫。你想在什么动作上调用该方法???加载片段后,我想调用该方法。