Edittext没有获取用户输入的值

时间:2014-09-03 13:17:11

标签: android list android-edittext

在我的应用程序中有一个编辑文本,下面有一个带复选框的列表。当用户选择一个特定复选框时,该值正在edittext中显示。如果用户在edittext中写入一些值然后选择复选框,然后用户输入的值被所选值覆盖。我希望这两个值都显示在edittext中

代码

public class EmailListAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<EmailModel> data;
    DbHandler dbHandler;
    int[] emails;
    static ArrayList<String> emailSeperated;
    private String strEmails, strTemp;

    public EmailListAdapter(Context context, ArrayList<EmailModel> data) {
        this.context = context;
        this.data = data;
        emails = new int[data.size()];
        emailSeperated = new ArrayList<String>();

    }

    @Override

    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        final ViewHolder holder;
        dbHandler = new DbHandler(context);


        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.email_custom_list, viewGroup, false);
            holder.tvContact = (TextView) view.findViewById(R.id.tv_email_name);
            holder.checkBox = (CheckBox) view.findViewById(R.id.cb_email_checkbox);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
//        if (emails[i] == 0) {
//            holder.checkBox.setChecked(false);
//        } else {
//            holder.checkBox.setChecked(true);
//        }


        holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                                                       @Override
                                                       public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                                                           if (compoundButton == holder.checkBox) {
                                                               if (b) {
                                                                   emails[i] = 1;
                                                                   //dbHandler.updateContactList(data.get(i).getUserID(), 1);


//

                                                               } else {

                                                                   emails[i] = 0;
                                                               }
                                                           }

                                                       }
                                                   }

        );

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


                if (emails[i] == 1) {

                    emailSeperated.add(data.get(i).getEmail());
                    Log.e("Email values", emailSeperated.toString());
                    Log.e("Position", "" + i);


                } else if (emails[i] == 0) {

                    emailSeperated.remove(data.get(i).getEmail());
                    Log.e("Email values", emailSeperated.toString());
                    Log.e("Position", "" + i);
                }
                if (!TextUtils.isEmpty(ShareWithinpocketDocs.etEmailLists.getText().toString())) {

                    ShareWithinpocketDocs.etEmailLists.setText(ShareWithinpocketDocs.etEmailLists.getText().toString() + "," + emailSeperated.toString().subSequence(1, emailSeperated.toString().length() - 1));

                } else {
                    strTemp = emailSeperated.toString().substring(1, emailSeperated.toString().length() - 1);
                    Log.e("Email Seperated values", strTemp);
                    ShareWithinpocketDocs.etEmailLists.setText(strTemp);
                }
            }
        });


        if (emails[i] == 0) {
            holder.checkBox.setChecked(false);
//            emailSeperated.remove(data.get(i).getEmail());
//            Log.e("Email values", emailSeperated.toString());

//            ShareWithinpocketDocs.etEmailLists.setText(emailSeperated.toString());
        } else {
            holder.checkBox.setChecked(true);
//            emailSeperated.add(data.get(i).getEmail());
//            Log.e("Email values", emailSeperated.toString());

        }


        holder.tvContact.setText(data.get(i).getEmail());


        return view;
    }


    private class ViewHolder {
        TextView tvContact;
        CheckBox checkBox;

    }
}

1 个答案:

答案 0 :(得分:0)

这将显示EditText中当前的内容以及用逗号分隔的新文本。变化

holder.tvContact.setText(data.get(i).getEmail());

String s = holder.tvContact.gettext().toString();
holder.setText(s + ", " + data.get(i).getEmail());