I'm going crazy with Android programming. Nothing works properly..
Whats wrong with this?
Error: getIntent() is undefined for type View
Any ideas?
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_quiz, container,
false);
TextView text = (TextView)rootView.findViewById(R.id.ttv);
Bundle intentBundle = rootView.getIntent().getExtras();
int question_cat = intentBundle.getInt("question_cat");
text.setText(question_cat);
return rootView;
}
}
You can just do:
Intent intentBundle = getActivity().getIntent();
String question_cat = intentBundle.getStringExtra("question_cat");
Log.i("Result : ", question_cat);
Even after you get the value as string, you use it as a int value later like this :
int j = Integer.valueOf(question_cat);
Log.i("Result : ", String.valueOf(j));
For your other question, with getIntent(), the problem is that you are using it inside the fragment class and in order to use that, you have to use getActivity() to access it. If it was just a normal activity, it wasn't that complicated. Android is really fun if some concepts are clear .. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With