I am trying to check one check box from another checkbox listener in a list view. Here is my Code for the Listview Adapter. The Checkbox listener should be able to check a checkbox in any given position in the listview.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
DataSetTasks tasks = getItem(position);
final int FinalPos = position + 1;
final int LastPostition = getCount() -1;
final int FixedLastPosition = LastPostition +1;
connectionClass = new ConnectionClass();
final ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_layout_orderprogress, parent, false);
viewHolder = new ViewHolder();
viewHolder.TaskName = (TextView) convertView.findViewById(R.id.txtTaskName);
viewHolder.TaskStart = (CheckBox) convertView.findViewById(R.id.cbxStartTask);
viewHolder.TaskEnd = (CheckBox) convertView.findViewById(R.id.cbxEndTask);
viewHolder.TaskStart.setTag(position);
viewHolder.TaskEnd.setTag(position);
convertView.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.TaskStart.setClickable(position == 0);
viewHolder.TaskName.setText(tasks.TaskName);
viewHolder.TaskStart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton checkStart, boolean isChecked) {
if (checkStart.isChecked()){
final int TaskID = (Integer) checkStart.getTag() + 1;
new AlertDialog.Builder(getContext())
.setTitle("Start Task?")
.setMessage("Are you sure you want to start this task?")
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String DateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).format(Calendar.getInstance().getTime());
Toast.makeText(getContext(), "" + TaskID, Toast.LENGTH_SHORT).show();
if (TaskID == 1){
viewHolder.TaskEnd.setChecked(position ==3); // This doesn't want to work
}
else {
}
checkStart.setEnabled(false);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
checkStart.setChecked(false);
}
})
.show();
}
}
}
);
Any Help Will be extremely appreciated!!!
Aucun commentaire:
Enregistrer un commentaire