我有这个代码:
package com.app.BoomBase;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class CheckList extends Activity{
ImageButton bAddBoom, bAddTools, bAddCloth, bRemoveBoom, bRemoveTools, bRemoveCloth;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.check_list);
final LinearLayout llBooms = (LinearLayout) findViewById(R.id.llBooms);
ImageButton bAddBoom = (ImageButton) findViewById(R.id.bAddBoom);
bAddBoom.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog alert = new AlertDialog.Builder(CheckList.this).create();
final EditText input = new EditText(CheckList.this);
alert.setTitle("Name of category?");
alert.setView(input);
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String userin = input.getText().toString();
if(userin != null){
return;
}
else{
for(int i = 0; i < 1; i++) {
CheckBox cb1 = new CheckBox(getBaseContext());
cb1.setText(userin+i);
cb1.setId(i+1);
llBooms.addView(cb1);
}
}
}
});
alert.show();
alert.setButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
}
});
}
}
而且我无法弄清楚如何使复选框具有变量“userin”的名称..有人可以帮助我吗?另一个问题:我如何处理代码中新创建的复选框,以便我可以检查内容是否被选中?
谢谢 !