Android 滚动列表视图时,编辑文本值将被清除

Android 滚动列表视图时,编辑文本值将被清除,android,Android,我有一个布局,其中包含列表视图,其中将有编辑文本。 在编辑文本中输入数据和滚动文本屏幕后,编辑文本值被清除 我面临的问题是无法在屏幕滚动后保存编辑文本值 package com.nafaes.nafaesgate.Adaptors; import android.content.Context; import android.content.SharedPreferences; import android.text.Editable; import android.text.TextWatc

我有一个布局,其中包含列表视图,其中将有编辑文本。 在编辑文本中输入数据和滚动文本屏幕后,编辑文本值被清除

我面临的问题是无法在屏幕滚动后保存编辑文本值

package com.nafaes.nafaesgate.Adaptors;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.nafaes.nafaesgate.R;
import com.nafaes.nafaesgate.activities.BullionWithdrawActivity;
import com.nafaes.nafaesgate.activities.OrdersHistoryActivity;
import com.nafaes.nafaesgate.activities.ReserveActivity;


import java.util.ArrayList;

/**
 * Created by Mounika on 5/15/2017.
 */

public class BullionWithdraw_list extends BaseAdapter {
    ArrayList<String> barname_array=new ArrayList<String>();
    ArrayList<String> quantity_array=new ArrayList<String>();
    ArrayList<String> bullion_array=new ArrayList<String>();
    ArrayList<Integer> bullionId_array=new ArrayList<Integer>();
    ArrayList<Integer> detailsid=new ArrayList<Integer>();
    ArrayList<String> userOty_array=new ArrayList<String>();
    ArrayList<Double> bullionweight_array = new ArrayList<Double>();
    Double serCharges;
    Double barsTotal;
    Double finalCharges;
    String bullionvalue;
    Double quantityValue = 0.0;
    ArrayList<Integer> quantityValue_array = new ArrayList<Integer>();

    String bullionWithdrawvalue;
    String bullionSrveQuanEmp = "";
    Double bullionQuanFloat;
    String quanLimit;
    Double limitDouble;
    String limitQuantity = "";
    Double totalQuanVal;
    Double quanValue = 0.0;
    Double serviceChargeVal = 0.0;
    Double serviceChargeDouble;
    String emptyStrng = "";
    String serviceChargeEdit;
    Integer data = 0;
    String servicetext;
    String deliveryText;
    Double totalvalue = 0.0;
    Double serValue = 0.0;
    Integer  finaldelCharges;





    Context context;


    private static LayoutInflater inflater=null;

    public BullionWithdraw_list(BullionWithdrawActivity WithdrawActivity, ArrayList<String> barname_array,
                                ArrayList<String> quantity_array,
                                ArrayList<String> bullion_array,
                                ArrayList<Integer>bullionId_array,
                                ArrayList<String> userOty_array,
                                ArrayList<Integer> detailsid,
                                Double serCharges,
                                ArrayList<Double> bullionweight_array,Double serviceChargeDouble,ArrayList<Integer> quantityValue_array,String serviceChargeEdit
                                 )
    {

        this.barname_array=barname_array;
        this.quantity_array=quantity_array;
        this.bullion_array=bullion_array;
        this.bullionId_array=bullionId_array;
        this.detailsid=detailsid;
        this.userOty_array = userOty_array;
        this.serCharges = serCharges;
        this.bullionweight_array = bullionweight_array;
        this.serviceChargeDouble = serviceChargeDouble;
        this.quantityValue_array = quantityValue_array;
        this.serviceChargeEdit = serviceChargeEdit;



        context=WithdrawActivity;



        inflater = ( LayoutInflater )context.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        Log.e("Service","63 "+serCharges);
        Log.e("De","63 "+detailsid);


    }

    @Override
    public int getCount() {
        return bullionId_array.size();
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    @Override

    public Object getItem(int position) {
        return position;
    }

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

    public class Holder
    {
        TextView tv1,tv2;
        EditText et1;
        int pos;

    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final BullionWithdraw_list.Holder holder=new BullionWithdraw_list.Holder();
        View rowView;
        rowView = inflater.inflate(R.layout.bullion_withdraw_list, null);
        holder.tv1=(TextView) rowView.findViewById(R.id.barname);
        holder.tv2=(TextView)rowView.findViewById(R.id.quantity);
        holder.et1=(EditText) rowView.findViewById(R.id.withdraw);
        rowView.setTag(holder);

        Log.e("QuanArray","143 "+quantityValue_array);
        Log.e("Weight Array","148 "+bullionweight_array);

        quanValue = 0.0;
        serviceChargeVal = 0.0;


        holder.tv1.setText(barname_array.get(position));
        holder.tv2.setText(quantity_array.get(position));




        //quantityValue_array.clear();
        holder.et1.addTextChangedListener(new TextWatcher() {


            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }


            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                //if (quantityValue_array.g)

                SharedPreferences preferences = context.getSharedPreferences("finalcharges",Context.MODE_PRIVATE);
                finaldelCharges = preferences.getInt("finalcharges",0);
                Log.e("Prefs","179 "+finaldelCharges);

                serviceChargeEdit = "0.0";
                serviceChargeVal = 0.0;
                quanValue = 0.0;

                holder.et1.setTag(position);

                if (!holder.et1.getText().toString().trim().equals("")) {
                    //quantityValue_array.add(holder.et1.getText().toString());
                    quantityValue_array.set(position, Integer.valueOf(holder.et1.getText().toString()));
                    Log.e("List", "172 " + quantityValue_array);

                } else {
                    quantityValue_array.set(position, 0);
                }
                Log.e("ListEditText", "172 " + quantityValue_array);
                Log.e("Weight", "187 " + bullionweight_array);
                    serValue = 0.0;
                for (int j = 0;j<quantityValue_array.size();j++){
                    serValue =  serValue + quantityValue_array.get(j) * bullionweight_array.get(j) * serCharges;
                    Log.e("Charges at row number","196 "+ j +"  is " + serValue);


                }
                totalvalue = serValue+finaldelCharges;

                String finalserCharges = String.valueOf(serValue);
                Log.e("Text","208 "+totalvalue);
                ((BullionWithdrawActivity) context).callMethod(finalserCharges,detailsid);


            }



            @Override
            public void afterTextChanged(Editable editable) {

            }
        });


        rowView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(context, AddCart.class);
//                context.startActivity(intent);

            }
        });
        return rowView;
    }

}
包com.nafaes.nafaesgate.adapters;
导入android.content.Context;
导入android.content.SharedReferences;
导入android.text.Editable;
导入android.text.TextWatcher;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.MotionEvent;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.BaseAdapter;
导入android.widget.EditText;
导入android.widget.TextView;
导入com.nafaes.nafasgate.R;
导入com.nafaes.nafaesgate.activities.bullionactivity;
导入com.nafaes.nafasgate.activities.OrdersHistoryActivity;
导入com.nafaes.nafasgate.activities.ReserveActivity;
导入java.util.ArrayList;
/**
*由Mounika于2017年5月15日创建。
*/
公共类BullionDraw_列表扩展BaseAdapter{
ArrayList barname_数组=新的ArrayList();
ArrayList数量_数组=新ArrayList();
ArrayList bullion_数组=新的ArrayList();
ArrayList bullionId_数组=新的ArrayList();
ArrayList detailsid=新的ArrayList();
ArrayList userOty_array=新的ArrayList();
ArrayList bullionweight_数组=新的ArrayList();
双重收费;
双柱头;
双重收费;
金条价值;
双数量值=0.0;
ArrayList quantityValue_数组=新的ArrayList();
字符串值;
字符串bullingsrvequanemp=“”;
双黄金全流通;
字符串数量限制;
双限双;
字符串limitQuantity=“”;
双总量程;
双量子值=0.0;
双重服务费用VAL=0.0;
双倍服务收费双倍;
字符串emptyStrng=“”;
字符串编辑;
整数数据=0;
字符串服务文本;
字符串传递文本;
双倍总值=0.0;
双serValue=0.0;
整数最终收费;
语境;
专用静态充气机=空;
公共金条提取列表(金条提取活动提取活动,ArrayList barname\u数组,
ArrayList数量\u数组,
ArrayList bullion_数组,
ArrayListbullionId_数组,
ArrayList userOty_数组,
ArrayList detailsid,
双重指控,
ArrayList bullionweight\u数组,双服务ChargeDouble,ArrayList quantityValue\u数组,字符串服务ChargeEdit
)
{
this.barname_数组=barname_数组;
这个.quantity\u数组=quantity\u数组;
这个.bullion\u数组=bullion\u数组;
this.bullionId_数组=bullionId_数组;
this.detailsid=detailsid;
this.userOty_数组=userOty_数组;
this.serCharges=serCharges;
this.bullionweight\u数组=bullionweight\u数组;
this.serviceChargeDouble=serviceChargeDouble;
this.quantityValue\u数组=quantityValue\u数组;
this.serviceChargeEdit=serviceChargeEdit;
上下文=活动;
充气器=(充气器)上下文。
getSystemService(上下文布局\充气机\服务);
Log.e(“服务”、“63”+服务费);
日志e(“De”,“63”+详细信息SID);
}
@凌驾
public int getCount(){
返回bullionId_array.size();
}
公共上下文getContext(){
返回上下文;
}
公共void setContext(上下文){
this.context=上下文;
}
@凌驾
公共对象getItem(int位置){
返回位置;
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
公共类持有者
{
文本视图tv1、tv2;
编辑文本et1;
int pos;
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
最终金条撤回清单。持有人=新金条撤回清单。持有人();
视图行视图;
rowView=充气机。充气(R.layout.bullion\u Draw\u list,空);
holder.tv1=(TextView)rowView.findviewbyd(R.id.barname);
holder.tv2=(TextView)rowView.findViewById(R.id.quantity);
holder.et1=(EditText)rowView.findViewById(R.id.draw);
rowView.setTag(支架);
Log.e(“QuanArray”、“143”+quantityValue_数组);
Log.e(“权重数组”,“148”+黄金权重数组);
数值=0.0;
serviceChargeVal=0.0;
holder.tv1.setText(barname_数组.get(位置));
holder.tv2.setText(quantity_array.get(position));
//quantityValue_数组.clear();
holder.et1.addTextChangedListener(新的TextWatcher(){
@凌驾
更改前的公共无效(CharSequence CharSequence,int i,int i1,int i2){
}
@凌驾
public void onTextChanged(CharSequence CharSequence,int i,int i1,int i2){
//if(quantityValue_array.g)
SharedReferences首选项=context.getSharedReferences(“最终收费”,context.MODE\u PRIVATE);
最终收费=preferences.getInt(“最终收费”,0);
Log.e(“优先”,“179”+最终收费);
serviceChargeEdit=“0.0”;
serviceChargeVal=0.0;
数值=0.0;
支架.et1.setTag(位置);
如果(!holder.et1.getText().toString().trim()等于(“”){
//quantityValue_array.add(holder.et1.getText().toString());
quantityValue_array.set(位置,Integer.valueOf(holder.et1.getText().toString());
Log.e(“列表”、“172”+数量值_数组);
if (convertView == null) {

    holder = new ViewHolder();

    LayoutInflater vi = (LayoutInflater)    
    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = vi.inflate(R.layout.bullion_withdraw_list, null);

    holder.et1= (EditText) convertView
            .findViewById(R.id.elementUpdateScore);


    convertView.setTag(holder);

} else {

    holder = (ViewHolder) convertView.getTag();

}
    //binding data from array list
    holder.et1.setText(et1[position]);
    holder.et1.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start,
                int before, int count) {
            //setting data to array, when changed
            et1[position] = s.toString();
      //rest your code
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start,
                int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

return convertView;