Android 尝试通过复选框删除自定义待办事项列表每行的膨胀视图时出现问题?

Android 尝试通过复选框删除自定义待办事项列表每行的膨胀视图时出现问题?,android,listview,checkbox,android-studio,Android,Listview,Checkbox,Android Studio,我正在通过可编辑文本填充listview,listview是定制的,每一行都包含一个textview和一个复选框,现在我希望通过单击复选框并通过delete按钮删除这些复选框来删除视图中的每一行,但我如何操作值。get(position)withtodoCheckBox.isChecked()这样我就可以删除每一个位置,第二,我如何删除之前我做过的每一行的膨胀视图值。删除(位置),但这只删除了arraylist和todoTextView.setText(“”)中的元素仅更改了textview的文

我正在通过可编辑文本填充listview,listview是定制的,每一行都包含一个textview和一个复选框,现在我希望通过单击复选框并通过delete按钮删除这些复选框来删除视图中的每一行,但我如何操作
值。get(position)
with
todoCheckBox.isChecked()
这样我就可以删除每一个位置,第二,我如何删除之前我做过的每一行的膨胀视图
值。删除(位置)
,但这只删除了arraylist和
todoTextView.setText(“”)中的元素
仅更改了textview的文本,但行的视图仍然存在

请记住我是这里的初学者

public class todoFragment extends ListFragment{

private EditText mToDoField;
private Button mAdd;
private Button mDelete;
UsersAdapter mAdapter;
private TextView todoTextView;
private CheckBox todoCheckBox;
ListView listViewToDo;
String val;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.todo_title);
}

public class UsersAdapter extends ArrayAdapter<String>{

public Context context;
public ArrayList<String> values;

public UsersAdapter(Context context, ArrayList<String> values) {
    super(context, 0, values);

    this.context = context;
    this.values = values;
}

@Override
public View getView(final int position, View convertView, final ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    convertView = LayoutInflater.from(getContext()).inflate(R.layout.todo_list, parent, false);

    todoTextView = (TextView) convertView.findViewById(R.id.todo_TextView);
    todoCheckBox = (CheckBox) convertView.findViewById(R.id.todo_CheckBox);

    todoTextView.setText(values.get(position));

    todoCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          //Toast.makeText(getContext(), " CheckBox Status: " + isChecked, Toast.LENGTH_LONG).show();

          if (todoCheckBox.isChecked()){

              val = "true";
              values.get(position).contains(val);
          }


          mDelete.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {

                  if (mDelete.isPressed() && (values.get(position).contains(val))){

                     //convertView.clearFocus(position);

                      todoTextView.setText("");

                  }
              }
          });


      }
     });

    return convertView;
}
}



@TargetApi(9) // remember this for isEmpty()
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                     Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_todo, container, false);

ArrayList<String> todoList = new ArrayList<String>();
mAdapter = new UsersAdapter(getActivity(), todoList);
listViewToDo = (ListView) v.findViewById (android.R.id.list);
listViewToDo.setAdapter(mAdapter);

mToDoField = (EditText) v.findViewById(R.id.todo_editText);
mDelete = (Button) v.findViewById(R.id.delete_button);

mAdd = (Button)v.findViewById(R.id.add_button);
mAdd.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View view) {

        String toDo = mToDoField.getText().toString().trim();

        if (toDo.isEmpty()){
            return;
        }

        mAdapter.add(toDo);

        mToDoField.setText("");
    }
});

return v;
}
公共类todoFragment扩展了ListFragment{
私有编辑文本字段;
私人按钮;
专用按钮mDelete;
UsersAdapter mAdapter;
私有文本视图到文本视图;
私有复选框todoCheckBox;
ListView listViewToDo;
字符串val;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.todo_title);
}
公共类UsersAdapter扩展了ArrayAdapter{
公共语境;
公共ArrayList价值观;
public UsersAdapter(上下文、ArrayList值){
super(上下文,0,值);
this.context=上下文;
这个值=值;
}
@凌驾
公共视图getView(最终整型位置、视图转换视图、最终视图组父视图){
LayoutFlater充气器=(LayoutFlater)上下文
.getSystemService(上下文布局\充气机\服务);
convertView=LayoutInflater.from(getContext()).flate(R.layout.todo_list,parent,false);
todoTextView=(TextView)convertView.findViewById(R.id.todo_TextView);
todoCheckBox=(复选框)convertView.findViewById(R.id.todo_复选框);
todoTextView.setText(values.get(position));
todoCheckBox.setOnCheckedChangeListener(新的CompoundButton.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(复合按钮视图,布尔值已检查){
//Toast.makeText(getContext(),“复选框状态:+isChecked,Toast.LENGTH_LONG).show();
if(todoCheckBox.isChecked()){
val=“true”;
value.get(position).contains(val);
}
mDelete.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
if(mDelete.isPressed()&&(values.get(position).contains(val))){
//convertView.clearFocus(位置);
todoTextView.setText(“”);
}
}
});
}
});
返回视图;
}
}
@TargetApi(9)//记住这一点
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图v=充气机。充气(R.layout.fragment_todo,容器,错误);
ArrayList todoList=新的ArrayList();
mAdapter=newusersadapter(getActivity(),todoList);
listViewToDo=(ListView)v.findViewById(android.R.id.list);
listViewToDo.setAdapter(mAdapter);
mToDoField=(EditText)v.findViewById(R.id.todo_EditText);
mDelete=(按钮)v.findviewbyd(R.id.delete_按钮);
mAdd=(按钮)v.findviewbyd(R.id.add_按钮);
mAdd.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
字符串toDo=mToDoField.getText().toString().trim();
if(toDo.isEmpty()){
回来
}
mAdapter.add(待办事项);
mToDoField.setText(“”);
}
});
返回v;
}

保留
值。删除(位置)
,然后在适配器上调用
notifyDataSetChanged()