调用片段方法?

时间:2015-10-06 10:33:10

标签: java android android-fragments methods

我有这个代码进入maim

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()"什么时候创建动作?

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

有什么想法吗?

0 个答案:

没有答案
相关问题