Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
扩展ListActivity的类中的android按钮_Android - Fatal编程技术网

扩展ListActivity的类中的android按钮

扩展ListActivity的类中的android按钮,android,Android,在扩展ListActivity的类中,我创建的每个项都显示为多个项。我只想在我的UI底部有一个按钮…问题是,当我创建这个按钮时,它显示为一个按钮列表,这不是我想要的…我只需要一个按钮…有人能帮我吗? 这是我的密码 public class ListViewActivity extends ListActivity implements OnCheckedChangeListener { TextView label; CheckBox checkBox; private ArrayList&l

在扩展ListActivity的类中,我创建的每个项都显示为多个项。我只想在我的UI底部有一个按钮…问题是,当我创建这个按钮时,它显示为一个按钮列表,这不是我想要的…我只需要一个按钮…有人能帮我吗? 这是我的密码

public class ListViewActivity extends ListActivity implements OnCheckedChangeListener {

TextView label;
CheckBox checkBox;
private ArrayList<Boolean> status = new ArrayList<Boolean>();

public class MyCustomAdapter extends ArrayAdapter<String> {


public MyCustomAdapter(Context context, int textViewResourceId,
  String[] objects) {

    super(context, textViewResourceId, objects);

    for (int i = 0; i < objects.length; i++) {
        status.add(false);
    }
  // TODO Auto-generated constructor stub
 }

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
 // TODO Auto-generated method stub
 //return super.getView(position, convertView, parent);

 View row = convertView;

 if(row==null){
  LayoutInflater inflater=getLayoutInflater();
  row=inflater.inflate(R.layout.main, parent, false); 

 }  


 label=(TextView)row.findViewById(R.id.months);
 label.setText(month[position]);



 checkBox=(CheckBox)row.findViewById(R.id.checkBox);
 checkBox.setFocusable(false);
 checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

 @Override
 public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

         String event = null;

         if (isChecked) 
         {
         status.set(position, true);
         event = " just checked!";
         } 

        else 
         {
         status.set(position, false);
         event = " just unchecked!";
         }

         Toast.makeText(getApplicationContext(), "checkbox " + position +event,    Toast.LENGTH_SHORT).show();   

 }
 });
 checkBox.setChecked(status.get(position));



 return row;
}
}

String[] month = {
    "January", "February", "March", "April",
    "May", "June", "July", "August",
    "September", "October", "November", "December"
  };

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 // setContentView(R.layout.main);
 /*setListAdapter(new ArrayAdapter<String>(this,
   R.layout.row, R.id.weekofday, DayOfWeek));*/


   setListAdapter(new MyCustomAdapter(ListViewActivity.this, R.layout.main, month));


   //here are the button I am talking about     
   Button saveButton = (Button) this.findViewById(R.id.button1);




  }


  }

如果只希望底部有一个按钮,则可以将该按钮定位在listview下方,或使用页脚视图,如下所述:


如何在listview下方定位?你能给我发个xml吗?问题是我没有在xml中定义任何listView,所以我怎么能把它放在listView下面呢?你是在把listView添加到某个容器中,对吗?在添加ListView后添加按钮我这样做了,但是我得到了一个运行时错误,button b=button this.findViewByIdR.id.button1;ListView lv=this.getListView;lv.addFooterViewb;设置适配器后,无法添加页脚视图。您必须删除适配器,设置页脚,然后设置适配器。ListView真是那样的蹩脚。