【问题标题】:android button in a class that extends ListActivity扩展 ListActivity 的类中的 android 按钮
【发布时间】:2012-04-10 02:26:30
【问题描述】:

在扩展 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);




  }


  }

【问题讨论】:

    标签: android


    【解决方案1】:

    如果您只希望底部有一个按钮,则可以将按钮置于列表视图下方,或使用此处所述的页脚视图:

    Android ListView Footer View not being placed on the bottom of the screen

    【讨论】:

    • 如何在列表视图下方定位?你能把那个xml发给我吗?
    • 问题是我没有在我的xml中定义任何listView,那我怎么把它放在ListView下面呢?
    • 您将列表视图添加到某个容器中对吗?添加列表视图后添加按钮
    • 我这样做了,但出现了运行时错误,Button b = (Button) this.findViewById(R.id.button1);ListView lv= this.getListView();lv.addFooterView(b);
    • 适配器设置后无法添加页脚视图。您必须卸下适配器,设置页脚,然后设置适配器。 ListView 那样真的很蹩脚。
    猜你喜欢
    • 1970-01-01
    • 2016-03-23
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    相关资源
    最近更新 更多