如何从列表视图中获取编辑文本值



我无法从动态列表视图中获取edittext值。当我滚动列表视图时,编辑文本中输入的值将不可见下面是我的活动文件-

   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_servic_homepage);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    url = getResources().getString(R.string.webservice);
    aq = new AQuery(ServicHomepage.this);
    cd = new ConnectionDetector(ServicHomepage.this);
    findviewbyId();
    progressdialog();
    if (cd.isConnectingToInternet()) {
        getintentData();
    } else {
        Toast.makeText(ServicHomepage.this, "CheckIternet connection",     Toast.LENGTH_SHORT).show();
    }
}
private void progressdialog() {
    pd = new ProgressDialog(ServicHomepage.this);
    pd.setMessage("Loading...");
}
public void findviewbyId() {
    recyclerview = (ListView) findViewById(R.id.service_recycler_view);
    update_descrptn = (TextView) findViewById(R.id.update_descrptn);
    uploadimages = (TextView) findViewById(R.id.uploadimages);
}
public void getintentData() {
    SharedPreferences prefs = getSharedPreferences(Constants.PREFS_NAME, 0);
    catid = prefs.getString(Constants.CATID, "");
    subcatid = prefs.getString(Constants.SUBCATID, "");
    user_id = prefs.getString(Constants.USERID, "");
    isappointment = prefs.getString(Constants.IS_APPOINTMENT, "");
    clicklistener();
}
public void clicklistener() {
    uploadimages.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), GalleryAlbumActivity.class);
            startActivity(i);
        }
    });
    update_descrptn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ServicHomepage.this, "" + serv_adapter.getItem(POSITION), Toast.LENGTH_SHORT).show();
            for (int i = 0; i < serv_adapter.getCount(); i++) {
                View view = serv_adapter.getView(i,null,null);
                EditText edittext = (EditText)view.findViewById(R.id.et_amount);
                EditText et_description = (EditText)view.findViewById(R.id.et_description);
                String str = edittext.getText().toString();
                String str1 = et_description.getText().toString();
                Toast.makeText(ServicHomepage.this, str + "==" + str1, Toast.LENGTH_SHORT).show();
            }
            updateList();
        }
    });
}
private void updateList() {
    String substring = null, msgString = "";
    String MAIN_CART = null;
    MAIN_CART = "{"service":[%s]}";
    String temstring = "";
    for (int i = 0; i < arrayList.size(); i++) {
        substring = "{"title":"" + arrayList.get(i).getTitle() + "","subcatid":"" + arrayList.get(i).getSubcatid()
                + "","amount":"" + "" + "","description":"" + "" + ""}" + ",";
        temstring = temstring + substring;
    }
    temstring = temstring.substring(0, temstring.length() - 1);
    msgString = msgString + String.format(MAIN_CART, temstring);
    Log.e("msgString=============", msgString);
}

这是将所有项目添加到列表中的方法

   public String parseanimcat(String object) {
    try {
        JSONObject json = new JSONObject(object);
        JSONObject jsonobj = json.getJSONObject("data");
        status1 = jsonobj.getString("status");
        message = jsonobj.getString("message");
        arrayList = new ArrayList<>();
        JSONArray jarray = jsonobj.getJSONArray("dataFound");
        for (int i = 0; i <= jarray.length(); i++) {
            JSONObject jobj = jarray.getJSONObject(i);
            String category = jobj.getString("category");
            String subsubcat_id = jobj.getString("subsubcat_id");
            Toast.makeText(ServicHomepage.this, category + "==" + subsubcat_id, Toast.LENGTH_SHORT).show();
            model = new Data_Model();
            model.setTitle(category);
            model.setSubcatid(subsubcat_id);
            arrayList.add(model);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return object;
}

这是我的适配器类-

    private class service_list_adapter extends ArrayAdapter<Data_Model>{
    private ArrayList<Data_Model> array_list;
    Context context;
    String[] etValArr;
    ViewHolder holder;
    String[] totalValue;
    Data_Model model;
    HashMap<String, String> hm = new HashMap<>();
    ArrayList<HashMap<String, String>> list = new ArrayList<>();
    public service_list_adapter(Context context,int   resourceId,ArrayList<Data_Model> arrayList) {
        super(context,resourceId,arrayList);
        this.context = context;
        this.array_list = arrayList;
        etValArr = new String[array_list.size()];
        totalValue = new String[array_list.size()];
    }
    private class ViewHolder {
        public TextView serv_title;
        public EditText serv_descrptn, serv_amount;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
          model = array_list.get(position);
        POSITION = position;
        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.serv_cat_rowitem, null);
            holder = new ViewHolder();
            holder.serv_title = (TextView) convertView.findViewById(R.id.serv_txt);
            holder.serv_descrptn = (EditText) convertView.findViewById(R.id.et_description);
            holder.serv_amount = (EditText) convertView.findViewById(R.id.et_amount);
            convertView.setTag(holder);
            holder.serv_title.setTag(position);
            holder.serv_descrptn.setTag(position);
            holder.serv_amount.setTag(position);
        } else
            holder = (ViewHolder) convertView.getTag();
        holder.serv_title.setText(model.getTitle());
        holder.serv_descrptn.setText(model.getServdescription());
        holder.serv_amount.setText(model.getServamount());
        holder.serv_amount.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void afterTextChanged(Editable s) {
                model.setServamount(s.toString());
            }
        });
        holder.serv_descrptn.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void afterTextChanged(Editable s) {
                model.setServdescription(s.toString());
            }
        });
        return convertView;
    }

}

更具体地说明您想要的editText值。您可以在列表上实现onScrollListner,并在该事件上保存editText的值,然后使用它

相关内容

  • 没有找到相关文章

最新更新