내 체크 박스 목록이 표시되고 있지만 나중에 사용할 수 있도록 xml에 저장할 목록 항목을 확인하고 싶습니다. 어떻게? 여기 내 목록 코드, 환경 설정 .. 내 체크 박스 목록을 저장하는 방법을 코드로 설명해주십시오.체크 박스를 클릭하면 내 체크리스트는 XML로 저장해야합니다. 어떻게해야합니까?
public class MachinesCheck extends Activity implements IObserver {
private StringBuffer buffer = new StringBuffer();
private ListView mainListView ;
private ArrayList<Machine> Machines ;
private ArrayList<Machine> SelectedMachines ;
private ArrayAdapter<Machine> listAdapter ;
Vector<MDCMachineStatus> machineStatus_vector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.machinecheck);
SelectedMachines = new ArrayList<Machine>();
MachineStatusSingleton.Register(this);
getData();
// Find the ListView resource.
mainListView = (ListView) findViewById(R.id.mainListView);
// When item is tapped, toggle checked properties of CheckBox and Planet.
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View item,
int position, long id) {
Machine machine = listAdapter.getItem(position);
machine.toggleChecked();
MachineViewHolder viewHolder = (MachineViewHolder) item.getTag();
viewHolder.getCheckBox().setChecked(machine.isChecked());
if (machine.checked)
{
SelectedMachines.add(machine);
}
else
{
SelectedMachines.remove(machine);
}
}
});
listAdapter = new MachineArrayAdapter(this, Machines);
mainListView.setAdapter(listAdapter);
mainListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
private void getData(){
machineStatus_vector = MachineStatusSingleton.GetData();
//arrayListofMachines = new ArrayList<String>();
//arrayListofMachineNumbers = new ArrayList<String>();
Machines = new ArrayList<Machine>();
for(MDCMachineStatus temp: machineStatus_vector){
//arrayListofMachines.add(temp.toString());
//arrayListofMachineNumbers.add(temp.getNumber());
Machines.add(new Machine(temp.toString(), temp.getNumber()));
}
}
private static class Machine {
private String name = "" ;
private String number ="";
private boolean checked = false ;
public Machine() {}
public Machine(String name, String number) {
this.name = name ;
this.number = number ;
}
public Machine(String name, boolean checked) {
this.name = name ;
this.checked = checked ;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public String toString() {
return name ;
}
public void toggleChecked() {
checked = !checked ;
}
}
private static class MachineViewHolder {
private CheckBox checkBox ;
private TextView textView ;
public MachineViewHolder(TextView textView, CheckBox checkBox) {
this.checkBox = checkBox ;
this.textView = textView ;
}
public CheckBox getCheckBox() {
return checkBox;
}
public void setCheckBox(CheckBox checkBox) {
this.checkBox = checkBox;
}
public TextView getTextView() {
return textView;
}
public void setTextView(TextView textView) {
this.textView = textView;
}
}
private static class MachineArrayAdapter extends ArrayAdapter<Machine> {
private LayoutInflater inflater;
public MachineArrayAdapter(Context context, List<Machine> machineList) {
super(context, R.layout.selectedlist, R.id.rowTextView, machineList);
// Cache the LayoutInflate to avoid asking for a new one each time.
inflater = LayoutInflater.from(context) ;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Machine to display
Machine machine = (Machine) this.getItem(position);
// The child views in each row.
CheckBox checkBox ;
TextView textView ;
// Create a new row view
if (convertView == null) {
convertView = inflater.inflate(R.layout.selectedlist, null);
// Find the child views.
textView = (TextView) convertView.findViewById(R.id.rowTextView);
checkBox = (CheckBox) convertView.findViewById(R.id.CheckBox01);
// Optimization: Tag the row with it's child views, so we don't have to
// call findViewById() later when we reuse the row.
convertView.setTag(new MachineViewHolder(textView,checkBox));
// If CheckBox is toggled, update the planet it is tagged with.
checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
Machine machine = (Machine) cb.getTag();
machine.setChecked(cb.isChecked());
}
});
}
// Reuse existing row view
else {
// Because we use a ViewHolder, we avoid having to call findViewById().
MachineViewHolder viewHolder = (MachineViewHolder) convertView.getTag();
checkBox = viewHolder.getCheckBox() ;
textView = viewHolder.getTextView() ;
}
// Tag the CheckBox with the Planet it is displaying, so that we can
// access the planet in onClick() when the CheckBox is toggled.
checkBox.setTag(machine);
// Display planet data
checkBox.setChecked(machine.isChecked());
textView.setText(machine.getName());
return convertView;
}
}
public Object onRetainNonConfigurationInstance() {
return Machines ;
}
public void Update(ISubject arg0) {
// TODO Auto-generated method stub
}
}
여기에 내 환경 설정을 확인하고 데이터가 어떻게 저장되는지 알려주세요.
<PreferenceScreen
android:key="DataEntryScreen"
android:title="Data Entry Machine"
android:summary="Select a Machine">
</PreferenceScreen>
: (.. 나를 –