如何获取用户选中的项目(复选框)

时间:2018-07-20 11:52:58

标签: cursor

Iam开发的应用程序,需要用户选择一些项目并将其发送到服务器。如何获取用户检查的项目。

@Override
public void onBindViewHolder(final ViewHolder holder, final int position)        
{

    ItemViewHolder itemView = (ItemViewHolder) holder;

    if (cursor != null){
        if (cursor.moveToPosition(position)){

            this.cursor.moveToPosition(position);
            int idIndex = cursor.getColumnIndex(ProblemsContract.ProblemEntries._ID);
            int problemIndex = cursor.getColumnIndex(ProblemsContract.ProblemEntries.PROBLEMS);
            int priceIndex = cursor.getColumnIndex(ProblemsContract.ProblemEntries.PRICE);

            final String id = this.cursor.getString(idIndex);
            final String problems = this.cursor.getString(problemIndex);
            final String price = this.cursor.getString(priceIndex);
            //in some cases, it will prevent unwanted situations

            itemView.tvPrice.setText(price);
            itemView.tvProblems.setText(problems);
            itemView.tvProblems.setText(problems);


            itemView.cbProblems.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (buttonView.isPressed()){
                    mDataset.get(position - 1).setSelected(isChecked);
                    Toast.makeText(context, "postion " + position + "Boolean value " + Boolean.valueOf(isChecked), Toast.LENGTH_SHORT).show();;
            }

                }
            });
        }else{
            Log.e("info", "Cursor is null");
        }
    }
}

请任何人帮助我。

0 个答案:

没有答案