When my app launches, the first thing that happens is a fragment comes to the front with a yes/no question. Depending on your answer, it replaces itself with the appropriate fragment. But what's currently killing me is that the 2 button's onclicks aren't even being called. I've simplified the code for here.
What's weird is that when I run the same code in an Activity instead of a fragment, it works fine. Let me know what you think. Thank you
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
public class FirstLaunchFragment extends Fragment implements OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_first_launch, container,
false);
Button mYesButton = (Button) view.findViewById(R.id.b_yes_mom);
mYesButton.setOnClickListener(this);
Button mNoButton = (Button) view.findViewById(R.id.b_no_mom);
mNoButton.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.b_yes_mom:
Toast.makeText(getActivity(), "YES is clicked!",
Toast.LENGTH_LONG).show();
break;
case R.id.b_no_mom:
Toast.makeText(getActivity(), "NO is clicked!",
Toast.LENGTH_LONG).show();
break;
}
}
}
Here's the XML for the fragment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BCED91"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<ImageView
android:id="@+id/iv_stork_and_baby"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignLeft="@+id/textView1"
android:layout_alignTop="@+id/iv_stork_and_baby"
android:scaleType="fitCenter"
android:src="@drawable/storkbaby" />
<ImageView
android:id="@+id/iv_app_name_png"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/iv_stork_and_baby"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"
android:src="@drawable/cooltext1349499090" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/iv_stork_and_baby"
android:layout_centerHorizontal="true"
android:text="@string/are_you_mom" />
<Button
android:id="@+id/b_no_mom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/iv_stork_and_baby"
android:text="NO" />
<Button
android:id="@+id/b_yes_mom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_stork_and_baby"
android:layout_below="@+id/iv_stork_and_baby"
android:text="YES" />
</RelativeLayout>
!!!!!!!!! EDIT !!!!!!!!!
Because this has been making my brain itch, I created a new project, and started copying/pasting the code bit by bit to see what was breaking the functionality. At the end... it all worked. It's exactly the same as above but it works in this project but not the previous one. I think android was just being picky.
Thanks to everybody for all the help!!!