【问题标题】:Get all value in Listview Android获取 Listview Android 中的所有值
【发布时间】:2014-05-23 22:33:34
【问题描述】:

我在列表视图中遇到两个问题

当我在编辑文本和滚动列表视图上输入值时,编辑文本自动为空。

编辑文本不为空时,单击保存草稿按钮时无法获取所有列表视图行信息,非空编辑文本可能是一个或多个。

这里是我的列表视图适配器代码

class CreateAdapter extends ArrayAdapter<String> {  
    TextView txtItecode, txtItem;
    EditText editQuantity;
    String[] strItecode;
    String[] strItem;
    String[] strQuantity;
    Context context;

    CreateAdapter(Context context, String[] strItemcode, String[] strItem,
            String[] strQauntity) {
        super(context, R.layout.create_list_item, R.id.txtItemcode, strItemcode);
        this.context = context;
        this.strItecode = strItemcode;
        this.strItem = strItem;
        this.strQuantity = strQauntity;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View row = mInflater.inflate(R.layout.create_list_item, parent, false);

        txtItecode = (TextView) row.findViewById(R.id.txtItemcode);
        txtItem = (TextView) row.findViewById(R.id.txtItem);
        editQuantity = (EditText) row.findViewById(R.id.editcreateQuantity);

        txtItecode.setText(strItecode[position]);
        txtItem.setText(strItem[position]);
        editQuantity.setText(strQuantity[position]);

        return row;
    }
}

我是 Android 开发新手 请帮助我如何解决这个问题。

这两天一直在努力

【问题讨论】:

  • 您尚未在适配器中设置编辑文本。

标签: android listview android-listview android-custom-view


【解决方案1】:

试试这个,

class CreateAdapter extends ArrayAdapter<String> {
    String[] strItecode;
    String[] strItem;
    String[] strQuantity;
    Context context;

    CreateAdapter(Context context, String[] strItemcode, String[] strItem,
            String[] strQauntity) {
        super(context, R.layout.create_list_item, R.id.txtItemcode, strItemcode);
        this.context = context;
        this.strItecode = strItemcode;
        this.strItem = strItem;
        this.strQuantity = strQauntity;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {

            holder = new ViewHolder();
            convertView = mInflater
                    .inflate(R.layout.create_list_item, parent, false);

            holder.txtItecode = (TextView) convertView
                    .findViewById(R.id.txtItemcode);
            holder.txtItem = (TextView) convertView
                    .findViewById(R.id.txtItem);
            holder.editQuantity = (EditText) convertView
                    .findViewById(R.id.editcreateQuantity);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txtItecode.setText(strItecode[position]);
        holder.txtItem.setText(strItem[position]);
        holder.editQuantity.setText(strQuantity[position]);

        return convertView;
    }

    class ViewHolder {
        TextView txtItecode;
        TextView txtItem;
        EditText editQuantity;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    相关资源
    最近更新 更多