Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to place a fragment in my main activity(ReportFormActivity),which contains a customised listview.I want to inflate a custom layout containing 5 buttons and one spinner into it.I kEEP GETTING THE above error.Following is my complete code.

public class ReportFormActivity extends FragmentActivity  {




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_report_form);

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //forces the activity to be displayed in landscape mode.

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

public class ButtonRowFragment extends Fragment implements android.view.View.OnClickListener{

Button optionA;
Button optionB;
Button optionC;
Button optionD;
Button optionN;
Spinner interactiveTaskSpinner;
ListView list;
ButtonAdapter adapter;
public ButtonRowFragment CustomListView = null;
public ArrayList<ListModel> CustomListViewValuesArr = new ArrayList<ListModel>();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    //watch out here
    View view= inflater.inflate(R.layout.listview, container, false);

    CustomListView = this;
    setListData();
    Resources res = getResources();
    list = (ListView)getView().findViewById(R.id.list); 
    adapter = new ButtonAdapter(CustomListView, CustomListViewValuesArr,res);
    list.setAdapter(adapter);

     optionA=(Button)view.findViewById(R.id.button1);
     optionB=(Button)view.findViewById(R.id.button2);
     optionC=(Button)view.findViewById(R.id.button3);
     optionD=(Button)view.findViewById(R.id.button4);
     optionN=(Button)view.findViewById(R.id.button5);



           optionA.setOnClickListener(this);
           optionB.setOnClickListener(this);
           optionC.setOnClickListener(this);
           optionD.setOnClickListener(this);
           optionN.setOnClickListener(this);

           interactiveTaskSpinner = (Spinner)view. findViewById(R.id.interactive_task_spinner);
    return view;
}

public void setListData() {

    for (int i = 0; i < 11; i++) {

        final ListModel sched = new ListModel();

        /******* Firstly take data in model object ******/
        sched.setCompanyName("Button " + i);
        sched.setImage("Spinner" + i);


        sched.setUrl("http:\\www." + i + ".com");

        /******** Take Model Object in ArrayList **********/
        CustomListViewValuesArr.add(sched);
    }
}       
    public void onItemClick(int mPosition)
    {
        ListModel tempValues = ( ListModel ) CustomListViewValuesArr.get(mPosition);


       // SHOW ALERT                  

       // Toast.makeText(CustomListView, ""+tempValues.getCompanyName() +" Image:"+tempValues.getImage() +" Url:"+tempValues.getUrl(), Toast.LENGTH_LONG).show();
    }

    @Override

        public void onClick(View view) {
            // TODO Auto-generated method stub
             switch(view.getId()){
             case R.id.button1:
                  //DO something
                 optionA.setBackgroundColor(getResources().getColor(R.color.green));

                 optionC.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionD.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionN.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionB.setBackgroundColor(getResources().getColor(R.color.purple));

             break;
             case R.id.button2:
                  //DO something
                 optionA.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionC.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionD.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionN.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionB.setBackgroundColor(getResources().getColor(R.color.green));
             break;
             case R.id.button3:
                  //DO something
                 optionA.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionD.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionN.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionB.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionC.setBackgroundColor(getResources().getColor(R.color.green));
             break;
             case R.id.button4:
                 //DO something
                 optionA.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionC.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionN.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionB.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionD.setBackgroundColor(getResources().getColor(R.color.green));
            break;
             case R.id.button5:
                 //DO something
                 optionA.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionC.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionD.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionB.setBackgroundColor(getResources().getColor(R.color.purple));
                 optionN.setBackgroundColor(getResources().getColor(R.color.green));
            break;
         }
        }
    }

This is the xml layout for the ReportFormActivity

Below is the layout for listview(meant to be inflated in the listview)

<?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="wrap_content"
android:padding="10dp"
android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Topic Presentation"
        android:textSize="19px" />

    <Button
        android:id="@+id/button1"
        android:layout_width="30dp"
        android:layout_height="30dip"
        android:background="@color/Purple"
        android:text="A"
        android:layout_marginLeft="30dp"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button2"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="20dp"
        android:background="@color/Purple"
        android:text="B"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button3"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="20dp"
        android:background="@color/Purple"
        android:text="C"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button4"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="20dp"
        android:background="@color/Purple"
        android:text="D"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_marginLeft="20dp"
        android:background="@color/Purple"
        android:text="NTP"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="bold" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="31dp" />

</LinearLayout>   
share|improve this question
1  
post your listview layout –  M D Jun 28 at 13:47
    
Added.Please check –  user3786018 Jun 29 at 15:46
    
where is your list coming from?> –  M D Jun 29 at 16:08
    
The list(layout) is meant to be inflated in the listview inflated within the fragment. –  user3786018 Jul 3 at 9:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.