1

After spending enough time unsuccessfully, I am posting it here to seek help. I have a ListFragment called from the following FragmentActivity. In the Layout there is a Submit button on top, so that user can scroll the list and press the Submit button when done with filling in the information. However I can't click this submit button. It never gets focus. How can I fix it?

Thanks for your help.

I have this FragmentActivity:

public class SurveyFragmentAnchor extends FragmentActivity {

Button submit; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_survey_fragment);
    setTitle("Feedback and Survey");

    submit = (Button) findViewById(R.id.submit_button);

    submit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
             Log.v("SURVEY", "Button pressed");
        }
    });
}
}

And here is the Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="4dp" >

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#e5e5e5">

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="#ee000000" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:paddingBottom="10dp"
            android:text="Rating (1-5) 5= Excellent, 4=Very good, 3=Good,\n2= Satisfactory, 1= Needs Improvement"
            android:textColor="#FFF" />

            <Button
                android:background="@drawable/button_blue2"
                android:textColor="#FFF"
                android:id="@+id/submit_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/my_survey_fragment"
                android:text="Submit" />


   </TableRow>
</TableLayout>      

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000"
        android:drawSelectorOnTop="false" >
    </ListView>
</LinearLayout>

<fragment
    android:name="com.survey.MySurvey"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="47dp"
    android:id="@+id/my_survey_fragment">
</fragment>

zeeshan
  • 4,913
  • 1
  • 49
  • 58
  • [Relevant answer](http://stackoverflow.com/questions/8577463/fragments-onclick-method-in-fragment-element) – wesdfgfgd Jun 26 '13 at 20:27
  • Based on the answer you referred to , why I put Button code inside the Fragment, it get the value for 'submit', meaning its not null, but still I can't click it. Problem is that button never comes to focus so it can't be clicked. – zeeshan Jun 26 '13 at 20:41
  • it must be a on a different view. – wesdfgfgd Jun 27 '13 at 13:58

1 Answers1

0

Try using these fields on the button:

android:focusable="true"
android:focusableInTouchMode="true"