0

So as of current I am making an Android application with multiple layout files that swap on a button click. Currently I am having an issue. I have a user click a button that opens an AlertDialog with multiple radio buttons, they select one then hit Ok. This sets a global CharSequence Then once they are sure that is what they want they will hit Done to go to the next screen. Here is the code for the Done button.

<Button android:layout_height="wrap_content" android:id="@+id/doneEventButton"       android:text="@string/doneEventButton" android:layout_width="138dp" android:onClick="nextEvent"></Button>

And here is the code for nextEvent.

public void nextEvent()
{
    if (eventVarString == "Send A Text")
    {
        setContentView(R.layout.send_text);
    }
    else if (eventVarString == "Make A Call")
    {
        setContentView(R.layout.make_call);
    }
    else if (eventVarString == "Open An App")
    {
        setContentView(R.layout.open_app);
    }
    else if (eventVarString == "Send An Email")
    {
        setContentView(R.layout.send_email);
    }
    else if (eventVarString == "Go To A Website")
    {
        setContentView(R.layout.go_to_a_website);
    }
}

Here is the code that pops up the AlertDialog and sets the global variable.

public void typeOfEvent(View v)
{
        final CharSequence[] items = {"Send A Text", "Make A Call", "Open An App", "Send An Email", "Go To A Website"};

        AlertDialog.Builder builder = new AlertDialog.Builder(SchedulerActivity.this);
        builder.setTitle("Choose An Event");
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                eventVarString = items[item];
         Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
            }
        });

        builder.setPositiveButton("Yes",
         new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
           TextView addEventVarText = (TextView) findViewById(R.id.eventChosen);
           addEventVarText.setText(eventVarString);
           Toast.makeText(SchedulerActivity.this, "Success", Toast.LENGTH_SHORT).show();
          }
         });
        builder.setNegativeButton("No",
         new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
           Toast.makeText(SchedulerActivity.this, "Fail", Toast.LENGTH_SHORT).show();
          }
         });
        AlertDialog alert = builder.create();
        alert.show();
}

And here is the LogCat that is generated from the Force Close when I click the Done button.

Pastebin.com

Cistoran
  • 1,587
  • 15
  • 36
  • 54

1 Answers1

3

Add the parameter View to the event handler.

public void nextEvent(View view)
wannik
  • 12,212
  • 11
  • 46
  • 58