2012-04-09 123 views
1

在擴展ListActivity的類中,我創建的每個項目都顯示爲多個項目。我想在我的用戶界面底部有「只有一個」按鈕....問題是,當我創建該按鈕時,它顯示爲不是我想要的按鈕列表...我只需要一個按鈕。 ...任何人都可以幫忙? 這裏是我的代碼,Android類擴展ListActivity中的android按鈕

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); 




    } 


    } 

回答

0

如果你只想要一個底部按鈕,然後您可以您的ListView下面的按鈕位置,或者使用頁腳觀點如下所述:

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

+0

如何在列表視圖的下方? 你可以發給我的XML嗎? – 2012-04-09 18:53:22

+0

問題是我沒有在我的xml中定義任何listView,那麼我如何將它定位在ListView之下? – 2012-04-09 18:57:33

+0

你正在添加列表視圖到一些容器是否正確?添加列表視圖後添加按鈕 – 2012-04-09 19:10:59