Hi 

This is my first android development project.  I am now stuck with a 
problem for several days and battle to get information on this.

I am developing an app with fragments (Listview and several detail view 
pages) Each detail fragment page have have a set of questions with 3 
radiobuttons to each question which is palced in a radiogroup per question. 
I have added a onClicklistener and switch to display the info clicked.  
This page have 8 questions with 24 radiobuttons and 8 radiogroups.

Each button click will also give a value to the question(1 or 0 or -1).  
This values will be calculated to give a compliance % to all the 
questions.  

My problem is that I don't get anything back from the Toast on my xml page 
when the radiobutton is click which tell me the onclicklistener is not 
working.  Can anyone please help me get this sorted out? 

Here is my coding:
Layout1.java

public class Layout1 extends Fragment {
    RadioGroup rgQ1, rgQ2, rgQ3, rgQ4, rgQ5, rgQ6, rgQ7, rgQ8;
    RadioButton q1t, q1f, q1na, q2t, q2f, q2na, q3t, q3f, q3na, q4t, q4f, q4na, 
q5t, q5f, q5na, q6t, q6f, q6na, q7t, q7f, q7na, q8t, q8f, q8na;
    EditText c1, c2, c3, c4, c5, c6, c7, c8;
    Button cnt1;
    private double value = 0;
    private int questions;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        final View V = inflater.inflate(R.layout.layout1, container, false);
        return V;
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        RadioButton q1t = (RadioButton) getActivity().findViewById(R.id.q1t);
        RadioButton q1f = (RadioButton) getActivity().findViewById(R.id.q1f);
        RadioButton q1na = (RadioButton) getActivity().findViewById(R.id.q1na);
        RadioButton q2t = (RadioButton) getActivity().findViewById(R.id.q2t);
        RadioButton q2f = (RadioButton) getActivity().findViewById(R.id.q2f);
        RadioButton q2na = (RadioButton) getActivity().findViewById(R.id.q2na);
        //then do other buttons ...

        q1t.setOnClickListener(next_Listener);
        q1f.setOnClickListener(next_Listener);
        q1na.setOnClickListener(next_Listener);
        q2t.setOnClickListener(next_Listener);
        q2f.setOnClickListener(next_Listener);
        q2na.setOnClickListener(next_Listener);
        //then do other buttons ...

    }
    private View.OnClickListener next_Listener = new View.OnClickListener() {
        public void onClick(View v) {
            switch (questions) {
                case R.id.rgQ1:
                    if (q1t.isChecked() == true) {
                        value = 1;
                        Toast.makeText(getActivity(), "Compliant", 
Toast.LENGTH_SHORT).show();
                    } else if (q1f.isChecked() == true) {
                        value = 0;
                        Toast.makeText(getActivity(), "Not Compliant", 
Toast.LENGTH_SHORT).show();
                    } else {
                        q1na.isChecked();
                        value = -1;
                        Toast.makeText(getActivity(), "Not Applicable", 
Toast.LENGTH_SHORT).show();
                    }
                    break;
                case R.id.rgQ2:
                    if (q2t.isChecked() == true) {
                        value = 1;
                        Toast.makeText(getActivity(), "Compliant", 
Toast.LENGTH_SHORT).show();
                    } else if (q2f.isChecked() == true) {
                        value = 0;
                        Toast.makeText(getActivity(), "Not Compliant", 
Toast.LENGTH_SHORT).show();
                    } else {
                        q2na.isChecked();
                        value = -1;
                        Toast.makeText(getActivity(), "Not Applicable", 
Toast.LENGTH_SHORT).show();
                    }
                    break;
            }
            }

    };
}


and layout1.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<TableLayout
    android:id="@+id/table_7"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow
        android:id="@+id/section7"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </TableRow>

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <TextView
            android:id="@+id/heading7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp"
            android:textColor="#000000"
            android:text="Section 7 - Health and Safety Policy"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginTop="40dp"
            android:layout_span="5">
        </TextView>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#EFF7FF">

            <TextView
                android:id="@+id/text_no7"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:padding="5dp"
                android:text="No"
                android:textColor="#000000"
                android:layout_marginLeft="0dp"
                
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

            <TextView
                android:id="@+id/question7"
                android:layout_width="400dp"
                android:layout_height="40dp"
                android:padding="5dp"
                android:textColor="#000000"
                android:text="Question"
                
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

            <TextView
                android:id="@+id/compliant7"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:padding="5dp"
                android:textColor="#000000"
                android:text="Compliance selection"
                
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

            </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#C8C2A7"
            android:textColor="#000000">

            <TextView
                android:id="@+id/q1"
                android:layout_width="10dp"
                android:layout_height="30dp"
                android:padding="5dp"
                android:text="1"
                android:textColor="#000000"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_marginLeft="0dp">
            </TextView>

            <TextView
                android:id="@+id/q1question"
                android:layout_width="400dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:textColor="#000000"
                android:text="Is the policy in writing?"
                
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
            <RadioGroup
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:id="@+id/rgQ1">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:id="@+id/q1t"
                android:layout_column="2"
                android:text="Compliant"
                android:checked="false"
                />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:id="@+id/q1f"
                android:checked="false"
                android:text="Not Compliant"
                />

            <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:id="@+id/q1na"
                android:checked="false"
                android:text="Not Applicable"
                />
            </RadioGroup>

        </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#C8C2A7"
        android:textColor="#000000">

        <EditText
            android:id="@+id/c1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_column="1"
            android:text="Insert Comment"
            android:textColor="#000000"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginLeft="0dp">
        </EditText>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#EFF7FF"
        android:textColor="#000000">

        <TextView
            android:id="@+id/q2"
            android:layout_width="10dp"
            android:layout_height="30dp"
            android:padding="5dp"
            android:text="2"
            android:textColor="#000000"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginLeft="0dp">
        </TextView>

        <TextView
            android:id="@+id/q2question"
            android:layout_width="400dp"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="#000000"
            android:text="Does the policy address the protection of employees?"
            
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/rgQ2">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:id="@+id/q2t"
                android:layout_column="2"
                android:text="Compliant"
                android:checked="false" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:id="@+id/q2f"
                android:checked="false"
                android:text="Not Compliant" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:id="@+id/q2na"
                android:checked="false"
                android:text="Not Applicable" />
        </RadioGroup>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#EFF7FF"
        android:textColor="#000000">

        <EditText
            android:id="@+id/c2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_column="1"
            android:text="Insert Comment"
            android:textColor="#000000"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginLeft="0dp">
        </EditText>

    </TableRow>


-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/faca9cd2-5abb-4ee4-9e46-42be32797e9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to