3

I have one listview inside the Custom Dialog. In that list i have one Text field and one Edittext for each row. I am using editTextWatcher for handling all edittext values on exact position. Up to this working fine. I have one save button on that dialog under the listView. After click on save i want to post the all editext data to server. But i am able to post only that values of edittext those are in front view.

Dialog Layout :

private void showDialog(){

    dialog1 = new Dialog(this);
    final Dialog tradDialog = new Dialog(this, android.R.style.Theme_Light_NoTitleBar);
    //tradDialog.setContentView(R.layout.trad_dialog_layout);
    View view = getLayoutInflater().inflate(R.layout.trad_dialog_layout_individual, null);
    //tradDialog.setContentView(R.layout.trad_dialog_layout);
    tradDialog.setCanceledOnTouchOutside(false);
   // holder.mWatcher = new MutableWatcher();
    lv = (ListView) view.findViewById(R.id.productsListView);
    RelativeLayout saveBtnLayout = (RelativeLayout) view.findViewById(R.id.saveBtnLayout);
    // Change MyActivity.this and myListOfItems to your own values
    clad = new CustomListAdapterDialog(SolutionActivity.this, individual_productChoosedAr);

    lv.setAdapter(clad);
    clad.notifyDataSetChanged();
  //save button for posting all edittext values to server 
    saveBtnLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            for (int i = 0; i < lv.getChildCount(); i++) {
                    v = lv.getChildAt(i);
                    etPrice = (EditText) v.findViewById(R.id.etPrice);
                    ProductPrice = etPrice.getText().toString();
                    if(ProductPrice.equals("")){
                        ProductPrice = "NULL";
                    }
                    productPriceAr.add(ProductPrice);
                }
            Toast toast = Toast.makeText(getApplicationContext(),"Please wait...",Toast.LENGTH_LONG);
            toast.show();
            SendIndividualDatatoServer sendIndividualData = new SendIndividualDatatoServer();
            sendIndividualData.execute();
        }
    });
    //lv.setOnItemClickListener(........);

    dialog1.setContentView(view);
    dialog1.show();

}

Custom Adatper :

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

        final int pos = position ;
        final ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.custom_layout_individual, null);
            holder = new ViewHolder();
            holder.product = (TextView) convertView.findViewById(R.id.tvProductName);
            holder.price = (EditText) convertView.findViewById((R.id.etPrice));
            holder.mWatcher = new MutableWatcher();
            holder.price.addTextChangedListener(holder.mWatcher);
            etPrice = (EditText) convertView.findViewById(R.id.etPrice);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
         holder.mWatcher.setActive(false);
        holder.price.setText(myList.get(position), TextView.BufferType.EDITABLE);
        holder.mWatcher.setPosition(position);
        holder.mWatcher.setActive(true);
        holder.product.setText(listData.get(position).P_Name);
        productIds = listData.get(position).Category_Id;
        return convertView;
    }

TextWatcher class:

@Override
    public void afterTextChanged(final Editable s) {
//            SolutionActivity.this.runOnUiThread(new Runnable() {
//                @Override
//                public void run() {
                if (mActive) {
                    myList.put(mPosition, s.toString());
                    System.out.print(s.toString());
                }
Preet Jay
  • 309
  • 4
  • 8

2 Answers2

0

What are you passing to your CustomAdapter ? You should use a custom object having the property which will contain the editText's text. So, you will pass an ArrayList myList of type custom object to the adapter. Whenever user types something, you get the position of the editText in the listview, then get the custom object at that position and write the editText value in the object's property.

Like this :

MyCustomClass object = myList.get(position);
object.setValue(edtText.getText());

Like this you will have all the data in the arrayList.

On save button click, you can loop through the arrayList and check individual object property, if it has data add it to your productPriceList.

Hope this helps!

intellignt_idiot
  • 1,962
  • 2
  • 16
  • 23
0

Finally i got answer myself: I counted list items and put only positions in Hashmap.

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        int mCount = lv.getCount();
        if(mIndCount==1){
            for(int i = 0; i<mCount;i++){
                myList.put(i,"");
            }
            mIndCount=2;
        }
    }

And for posting all values i used following :

for (int i = 0; i < myList.size(); i++) {
     if(myList.get(i).toString().equals("")){
                    ProductPrice = "NULL";
                }else {
                    ProductPrice = myList.get(i).toString();
                }

                    productPriceAr.add(ProductPrice);
                }
Preet Jay
  • 309
  • 4
  • 8