0

I have three buttons in my Activity with three separate onClickListeners set like I have done plenty times before. But one of the listeners does not react to a click event and I have no clue as to why. Here is the code segment:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_reminder_2);

    //References to layout resources
    edit2Back = (Button) findViewById(R.id.edit2Back);
    edit2Next = (Button) findViewById(R.id.edit2Next);
    edit2ChangeGPS = (Button) findViewById(R.id.edit2ChangeGPS);

    //Assigning listeners to Buttons
    edit2Back.setOnClickListener(listenerBack);
    edit2Next.setOnClickListener(listenerNext);
    edit2ChangeGPS.setOnClickListener(listenerChange);

}

final OnClickListener listenerNext = new OnClickListener() {

    public void onClick(View v) {
        Log.v("edit2Next","Click!");
        db.open();

        String sName = edit2ReminderName.getText().toString();
        String sNote = edit2ReminderText.getText().toString();
        int sRadius = Integer.parseInt(edit2Radius.getText().toString());
        String sUnits = (String) edit2SpinnerUnits.getSelectedItem();
        int sChecked = 0;
        if (edit2Check.isChecked()) {
            sChecked = 1;
        }

        db.insertReminder(sName, sNote, lat, lon, sRadius, sUnits, sChecked);

        db.close();

        Intent intent = new Intent(context, Reminders.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

}; 

All my other listener I wrote in the same fashion and they work perfectly fine, but this one does not. I looked all over the code but could not find the reason. The listener does not start at all, not even the Log.v instruction runs. Thanks for your advice!

EDIT:

This is part of the XML code where i define my Buttons:

<LinearLayout 
    android:id="@+id/edit2ControlLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/azure"
    android:padding="15dp"
    android:orientation="horizontal" >

    <Button 
        android:id="@+id/edit2Back"
        android:layout_height="wrap_content"
        android:layout_width="0.0dip"
        android:text="Back"
        android:background="@drawable/round_button_violet"
        android:textColor="@color/azure"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_weight="1.0"
        android:layout_marginRight="5dp" />

    <Button 
        android:id="@+id/edit2Next"
        android:layout_height="wrap_content"
        android:layout_width="0.0dip"
        android:text="Next"
        android:background="@drawable/round_button_violet"
        android:textColor="@color/azure"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_weight="1.0"
        android:enabled="false" />        


</LinearLayout>
4
  • 1
    Can we see the xml description of the Activity that specifies the buttons, please?
    – hcarver
    Aug 22, 2012 at 16:52
  • The code you have posted should work. I'll guess that you haven't assigned the id properly in the XML file, or maybe you need to clean and rebuild your project. Also, are you extending the Button class, or are these just normal Buttons?
    – you786
    Aug 22, 2012 at 17:07
  • I added the xml code. The edit2Back button works, but the edit2Next doesent :( Its really strange Aug 22, 2012 at 17:41
  • Oh god, now I noticed, I have enabled set to false! :( Sorry for the stupid question! Thanks for your help anyway;) Aug 22, 2012 at 17:43

1 Answer 1

1

Please remove android:enabled="false" in your next button code in-order to work next button.

<Button 
    android:id="@+id/edit2Next"
    android:layout_height="wrap_content"
    android:layout_width="0.0dip"
    android:text="Next"
    android:background="@drawable/round_button_violet"
    android:textColor="@color/azure"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:layout_weight="1.0"
    android:enabled="false" /> 
1
  • Already done it, I cant belive I didnt notice this. I guess thats what I get for overrecycling the code. Aug 22, 2012 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.