Passing data between fragments contained in an activity

前端 未结 2 671
广开言路
广开言路 2020-12-06 15:32

I have an activity A with 3 fragments. Each fragments replaces each other, hence at a given time only 1 is visible.

HomeFragment has 2 textviews wrapped inside 2 ca

2条回答
  •  没有蜡笔的小新
    2020-12-06 16:34

    how to pass values from activity to already open fragment and update array-list help me please. when I using interface the array-list size is zero what I do? do not us bundle method.

    public class Main2Activity extends AppCompatActivity{

    String desc = "data";
    OnDataPassedListener onDataPassedListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        String passedArg = getIntent().getExtras().getString("id");
        Log.d("data",passedArg);
        Scription scription = new Scription();
        onDataPassedListener = (OnDataPassedListener)scription;
        onDataPassedListener.onDataPassed(passedArg,desc);
    
    }
    public interface OnDataPassedListener {
        void onDataPassed(String text,String name);
    }
    

    }

    public class Test extends Fragment implements 
    

    Main2Activity.OnDataPassedListener{

    . . . . @Override

    public void onDataPassed(String text,String name) {
        monthlylists.get(Integer.valueOf(text)).setFood_type(name);
    }
    

提交回复
热议问题