I have this in the main activity :
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String forecast = mForecastAdapter.getItem(position);
Intent intent = new Intent(getActivity(),DetailActivity.class)
.putExtra(Intent.EXTRA_TEXT,forecast);
startActivity(intent);
}
});
the click is working because I tested it with TOAST earlier. I'm trying to pass that forecast string in the DetailActivity fragment, in a text view which initially shows "Hello world!". This is the code that I'm using :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Intent intent = getActivity().getIntent();
View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
if(intent != null && intent.hasExtra(Intent.EXTRA_TEXT)){
String forecastStr = intent.getStringExtra(Intent.EXTRA_TEXT);
((TextView) rootView.findViewById(R.id.detail_text)).setText(forecastStr);
}
return rootView;
}
The problem is that the if is never executed because I tested it with Log.v(TAG,"TestIfStatement");
What am I doing wrong ?