0

I have created an application in the past that switched from the first screen to the next when a button was clicked. I am trying to modify a new application to do similar, but instead have two screens to choose from. On the main screen are two radio buttons, and I want the corresponding view to appear depending on the user's selection. When I attempt to do this, though, no error appears on the program, but an error does popup when I try to run it. There is no error reported in the console nor the log. It only occurs after introducing my new xml file. My eventual goal is to create an application like MadLibs.

activity_main.xml:

<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" >

<TextView
    android:id="@+id/categoryTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="22dp"
    android:text="@string/cat" />

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/categoryTextView"
    android:layout_below="@+id/categoryTextView"
    android:layout_marginTop="14dp" >

    <RadioButton
        android:id="@+id/bkRadio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/bekind" />

    <RadioButton
        android:id="@+id/oldmcRadio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/oldmc" />


</RadioGroup>

<Button
    android:id="@+id/chooseButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/radioGroup1"
    android:layout_below="@+id/radioGroup1"
    android:layout_marginTop="18dp"
    android:text="@string/choose"
    android:onClick="buttonclick" />

</RelativeLayout>

bekindwords.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/nounKindTextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/noun" />

<EditText
    android:id="@+id/nounKindEditText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:ems="10" />

<TextView
    android:id="@+id/nounpKindTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/nounp" />

<EditText
    android:id="@+id/nounpKindEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:ems="10" />

<TextView
    android:id="@+id/nounKindTextView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/noun" />

<EditText
    android:id="@+id/nounKindEditText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:ems="10" />

   <TextView
    android:id="@+id/placeKindTextView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/place" />

<EditText
    android:id="@+id/placeKindEditText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:ems="10" />

<TextView
    android:id="@+id/adjKindTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/adj" />

<EditText
    android:id="@+id/@+id/adjKindEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:ems="10" />

<TextView
    android:id="@+id/nounKindTextView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/noun" />

<EditText
    android:id="@+id/nounKindEditText3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:ems="10" />

<Button
    android:id="@+id/enterButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="buttonclick2"
    android:text="@string/ent" />

</LinearLayout>

Main.java:

package com.deitel.adlibs;

import com.deitel.adlibs.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;

public class Main extends Activity {
//Global variable
        double bk;
        private Button choose;  // creates a button 

            @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            choose = (Button) findViewById(R.id.chooseButton);

            //Start with first screen
            setContentView(R.layout.activity_main);
        }

      //buttonclick for form 1
        public void buttonclick(View view){

            RadioButton bk = (RadioButton) findViewById(R.id.bkRadio);

             if(bk.isChecked())
            {
                //switch views to screen 2
                   setContentView(R.layout.bekindwords);  
            }

            }
             }
4

0 に答える 0