OnClickListener Does not Respond to Clicks in Fragment

I am transferring an old program over to a Tabs and Fragments implementation. The user inputs and Id for a search and then hits Submit. However my "Submit Button" does nothing.

I have tried several alternative coding variants but get same result - dead air!

Here is XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/setUpAthletesTab"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
     android:background="#CCFFFF" >

    <TextView
        android:id="@+id/instructionText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/instructionText"
    android:textColor="#FF0000"
    android:textAppearance="?android:attr/textAppearanceMedium"
     />

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:stretchColumns="*" >

        <EditText
            android:id="@+id/editTextAthlete0"
            android:layout_width="145dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:hint="@string/hintText"
            android:inputType="number" />

        <TextView
            android:id="@+id/textAthleteName0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:hint="@string/athleteHintName0"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </TableRow>

Here is my Tab / Fragment

public class Tab3Fragment extends Fragment {

    /* (non-Javadoc)
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        /* Begin Insertion */
        LayoutInflater myInflater = inflater;
        ViewGroup myContainer = container;
        if(inflater == null) myInflater = inflater;
        if(container == null) myContainer = container;
        Log.d(APP_TAG,"At line 50 of Tab3Fragment myInflater = " + myInflater + " and myContainer = " + myContainer);
        getAthleteInfoFromExistingDatabase(myInflater,myContainer);

        LinearLayout tab3LinearLayout = (LinearLayout) inflater.inflate(R.layout.tab_frag3_layout, container, false);

        View mySubmitButton = tab3LinearLayout.findViewById(R.id.submitButton);
        ((Button) mySubmitButton).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(Tab3Fragment.this.getActivity().getBaseContext(),
                        "clicked on Submit Button", Toast.LENGTH_LONG).show();

                Intent intent = new Intent();
                intent.setClass(getActivity(), RetrieveAthleteData.class);
                startActivity(intent);
            }
        });

        return (LinearLayout)inflater.inflate(R.layout.tab_frag3_layout, container, false);
    }

Neither the Toast box nor the Intent fire off when I hit submit.

Thanks for looking at my question.

Problem solved! Thanks Dirk for suggesting name change to all lower case.

Answers


In your xml is no Button with the id "submitButton".

You should only use lowercase and therefore give it the id "@+id/submit_button"

Although I could not find a source that camel case ids are not allowed. Even Google uses camel case ids in their examples sometimes.


You're inflating and returning a brand spanking new set of views here:

return (LinearLayout)inflater.inflate(R.layout.tab_frag3_layout, container, false);

you should be returning the inflated view's that you acted upon:

return tab3LinearLayout;

Need Your Help

Min-Width Table

asp.net html css table width

I am attempting to create a min-width table of 500px with a cell containing a textarea with a min-width of 300px. The table's min-width doesn't seem to be working at all. I'm using CSS to style the...

Dynamic table name in linq

c# linq entity-framework reflection

I'm trying to execute some LINQ commands using a dynamic table name. For example, instead of

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.