I can save the value in one variable, now I want to pass this variable to a fragment.
With the following code, I can upload fragments.
public class AndroidListFragmentActivity extends Activity {
Fragment2 f2;
public static String itemname;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.apetiserfragement);
itemname=getIntent().getStringExtra("itemname");
Bundle args=new Bundle();
args.putString("itemname", itemname);
f2=new Fragment2();
f2.setArguments(args);
}
}
(Here I load the snippet using the XML page) itemname
The output is divided into 2 windows, one for extension for listfragment (for list). One for fragments
Fragment2.xml
public class Fragment2 extends Fragment {
String itemname;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
System.out.println(getArguments().getString("itemname"));
return inflater.inflate(R.layout.fragment2, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
AndroidListFragmentActivity in this class itemname I need to pass Fragment2.class.
source
share