Passing value between activity to fragment on android

前端 未结 2 1771
猫巷女王i
猫巷女王i 2021-01-27 00:15

On Activity:

@Override
 public void onTabSelected(Tab tab, FragmentTransaction ft) {
 // on tab selected
 // show respected fragment view
  Log.         


        
相关标签:
2条回答
  • 2021-01-27 00:33

    Your Text is :

    int strtext=getArguments().getInt("Nilai", 0);
    

    It should Be:

    int strtext=getArguments().getInt("nilai", 0);
    

    Edit :

    Check Out this Question which is Related to your Problem:

    Here

    0 讨论(0)
  • 2021-01-27 00:43
        public class MyFragment extends Fragment {
            int strtext;
    
         @Override
        public void onCreate(Bundle savedInstanceState) 
              {
                super.onCreate(savedInstanceState);
                Bundle data = getArguments();
                strtext= data.getInt("Nilai");
              }
    
        @Override
         public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.lirik_view, container, false);
          Log.v("Testing", "Menjalankan proses pengambilan data dari activity");
    
          Log.v("Testing", "Data adalah "+strtext);
          return rootView;
         }
        }       
    
    0 讨论(0)
提交回复
热议问题