2014-09-26 1 views
0

이 질문은 자주 묻습니다. 그러나 나에게 도움이되는 것은 없습니다.edittext를 사용하여 listview가 스크롤 할 때 값을 반복합니다.

edittext 반복의 listview 값을 스크롤 할 때 edittext와 함께 listview가 있습니다.

주세요.

코드 : 현재 위치에 대한 글고의 값을 포함

public View getView(int position, View view, ViewGroup parent) { 

View mView = view;    //trying to reuse a recycled view 

    if (mView == null) { 
     //The view is not a recycled one: we have to inflate 
     mView = getActivity().getLayoutInflater().inflate(
       getResource(), parent, false); 
     holder = new ViewHolder(); 


     holder.row = (OEDataRow) moveLinesfinalData.get(position); 

     holder.eProductName = (TextView) mView.findViewById(R.id.textViewProductNameFinal); 
     holder.eProductName.setText(holder.row.getString("name").toString()); 

     holder.innerLinearLayout = (LinearLayout) mView 
       .findViewById(R.id.innerLinearLayout); 
     holder.editTextProductId = (EditText) holder.innerLinearLayout 
       .findViewById(R.id.editTextProductId); 
     holder.eProductSerial = (EditText) holder.innerLinearLayout 
       .findViewById(R.id.editTextSerialFinal); 

     holder.BarCode = (Button) holder.innerLinearLayout.findViewById(R.id.buttonBarcode); 
     holder.editTextProductIdFocus = (EditText) holder.innerLinearLayout 
       .findViewById(R.id.editTextProductId); 

     mView.setTag(holder); 
    } else { 
     // View recycled ! 
     // no need to inflate 
     // no need to findViews by id 
     holder = (ViewHolder) mView.getTag(); 
    } 

    if(holder.row != null) { 
     holder.editTextProductId.setText(holder.row.getInt("id").toString()); 

    } 

    holder.eProductSerial.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) { 
      String newSerial = s.toString(); 

      String id = holder.editTextProductIdFocus.getText().toString(); 
      productData.put(id,newSerial); 

     } 
    }); 

    Log.d("list", "list productData "+productData); 

    holder.BarCode.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      v.getId(); 
     } 
    }); 


    return mView; 
} 
+0

을 변경, 당신은 확인하기 위해'getView'에있는 경우 현재 행 (위치)는 정보가 저장되어있는 위치에 맞습니다. 그렇지 않다면, edittext 텍스트를 ""에 넣으십시오. – zozelfelfo

+0

[Android : EditText가 ListView의 스크롤에서 내용을 잃을 수 있습니까?] (http://stackoverflow.com/questions/9328301/android-edittext-loses-content-on-scroll-in-listview) – Gattsu

+0

@maven : I 이미 저를 위해 작동하지 않는 그 해결책을 시도했다. 배열 대신에 –

답변

0

당신은 문자열 (arrayStrings 같은)의 배열을 저장해야합니다.

arrayStrings[position]의 내용을 textChangedListener에 설정하십시오. 다음으로 getView에서 editText의 queryText를 현재 위치의 배열에있는 것으로 설정합니다. 그렇지 않으면 뷰가 재활용되므로 잘못된 동작이 예상됩니다. 대신

if(holder.row != null) { 
    holder.editTextProductId.setText(holder.row.getInt("id").toString()); 
} 

+0

나는 정적 LinkedHashMap를 사용하고있다 productData = new LinkedHashMap (); .. 작동하지 않습니다 –

0

는 HolderView에서

if(holder.row != null) { 
     holder.editTextProductId.setText(((OEDataRow) moveLinesfinalData.get(position)).getInt("id")); 
} 

가 아니라 일부 데이터 자체 만 조회수 ID를 유지합니다.

+0

작동하지 않습니다 날 치명적인 오류를 제공 –

+0

무슨 말을하는거야? –

+0

그것은 NoresourceFound라고 말합니다. –

0

제거 :

holder.row = (OEDataRow) moveLinesfinalData.get(position); 

과 당신의 EditText 값을 저장 한 후

if(holder.row != null) { 
     holder.editTextProductId.setText(holder.row.getInt("id").toString()); 
} 

if((OEDataRow) moveLinesfinalData.get(position) != null) { 
     holder.editTextProductId.setText(String.valueOf((OEDataRow) moveLinesfinalData.get(position)).getInt("id"))); 
} 
관련 문제