2013-07-22 2 views
2

안녕하세요 누구든지 나를 도와 줄 수 있습니까? 내 목록보기를 채우기 위해 사용자 지정 어댑터를 사용하고 있습니다. 내 listview에는 editText를 보유하는 해시 맵이 있습니다. 내 문제는 editText에 내용을 입력하고 listview를 스크롤하면 editText의 내용이 손실된다. 내가 지금 무엇을해야합니까? 아래 코드는 내 코드를 보여줍니다.리스트 뷰가 스크롤 될 때 editText의 값을 잃습니다.

************* 
myCustomAdapterIreport = new CustomArrayAdapterIreport(getApplicationContext(), mylist, R.layout.attribute_selected_ireport_file, 
            new String[]{FILE_NAME, DESC, UPLOADED_BY, DATE_UPLOADED, ACTION, ID, FILE_URI}, 
            new int[]{R.id.tv_iFile, R.id.txt_iDesc,R.id.tv_iUploadedBy,R.id.tv_iDateUploaded, R.id.tv_iAction, 
            R.id.tv_RowId, R.id.tv_iUri}, true); 
     lv_AttachedFileData.setAdapter(myCustomAdapterIreport); 

*********************** 


public class CustomArrayAdapterIreport extends SimpleAdapter 
{ 
    private Context context; 
    private final ArrayList<HashMap<String, String>> mData; 
    private ArrayList<HashMap<String, String>> unfilteredValues; 
    private boolean chosenValues, ismarkAll = true; 
    private int resource; 
    private String[] from; 
    private int[] to; 
    private SimpleFilter mFilter; 
    private ArrayList<String> arraylistAttach, arraylistAttachId; 

    S_10th_IReportMain iReport; 
    public CustomArrayAdapterIreport(Context context, ArrayList<HashMap<String, String>> data, int resource, String[] from, 
      int[] to, boolean chosenValues) 
    { 
     super(context, data, resource, from, to); 
     this.context = context; 
     mData = data; 
     this.unfilteredValues = mData; 
     this.resource = resource; 
     this.from = from; 
     this.to = to; 
     this.arraylistAttach = new ArrayList<String>(); 
     this.arraylistAttachId = new ArrayList<String>(); 
     this.chosenValues = chosenValues; 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) 
    { 
     LayoutInflater inflater = LayoutInflater.from(context); 
     View rowView = null; 

     if(rowView == null) 
     { 
      try{ 
       rowView = inflater.inflate(resource, null, true); 
       textViewTitle = (TextView) rowView.findViewById(to[0]); 
       txt_Desc = (EditText) rowView.findViewById(to[1]); 
       tv_CreatedBy = (TextView) rowView.findViewById(to[2]); 
       tv_DateCreated= (TextView) rowView.findViewById(to[3]); 
       final TextView tv_Action = (TextView) rowView.findViewById(to[4]); 
       final TextView tv_rowId = (TextView) rowView.findViewById(to[5]); 
       tv_Uri = (TextView)rowView.findViewById(to[6]); 

       Typeface tf= Typeface.createFromAsset(context.getAssets(), "Gothic_Regular.TTF"); 
       textViewTitle.setTypeface(tf); 
       txt_Desc.setTypeface(tf); 
       tv_CreatedBy.setTypeface(tf); 
       tv_DateCreated.setTypeface(tf); 
       tv_Action.setTypeface(tf); 

       final String FileKey = from[0]; 
       String DescKey = from[1]; 
       String UploadedByKey = from[2]; 
       String DateUploadKey = from[3]; 
       String ActionKey = from[4]; 
       final String idKey = from[5]; 
       String FileUri = from[6]; 

       final String FileName = unfilteredValues.get(position).get(FileKey).toString(); 
       String Desc = unfilteredValues.get(position).get(DescKey).toString(); 
       String UploadedBy = unfilteredValues.get(position).get(UploadedByKey).toString(); 
       String DateUpload = unfilteredValues.get(position).get(DateUploadKey).toString(); 
       String Action = unfilteredValues.get(position).get(ActionKey).toString(); 
       String AttachId = unfilteredValues.get(position).get(idKey).toString(); 
       String FileNameUri = unfilteredValues.get(position).get(FileUri).toString(); 

       textViewTitle.setText(FileName); 
       txt_Desc.setText(Desc); 
       tv_CreatedBy.setText(UploadedBy); 
       tv_DateCreated.setText(DateUpload); 
       tv_Action.setText(Action); 
       tv_rowId.setText(AttachId); 
       tv_Uri.setText(FileNameUri); 

       textViewTitle.setId(position); 
       txt_Desc.setId(position); 
       tv_CreatedBy.setId(position); 
       tv_DateCreated.setId(position); 
       tv_Uri.setId(position); 
       final String id = tv_rowId.getText().toString(); 
       tv_Action.setOnClickListener(new OnClickListener() 
       { 

        @Override 
        public void onClick(View view) 
        { 

         AlertDialog.Builder builder = new AlertDialog.Builder(S_10th_IReportMain.this); 
         builder 
         .setTitle("Warning!") 
         .setMessage("Are you sure you want delete this file?") 

         .setCancelable(false) 
         .setPositiveButton("Yes", new DialogInterface.OnClickListener() 
         {     
          @Override 
          public void onClick(DialogInterface dialog, int id) 
          { 

           deleteMyFilesiReport(position); 
           Toast.makeText(getApplicationContext(), "Deleted", Toast.LENGTH_SHORT).show(); 
          } 

         }) 
         .setNegativeButton("No", new DialogInterface.OnClickListener() 
         {     
          @Override 
          public void onClick(DialogInterface dialog, int id) 
          { 
           dialog.cancel(); 
          } 
         }); 

         AlertDialog alertDialog = builder.create(); 
         alertDialog.show(); 
        }              
        }); 



      }catch (Exception e){ 
       e.printStackTrace(); 
      } 
      catch (OutOfMemoryError E){ 
       E.printStackTrace(); 
      } 
     } 

     return rowView; 
    } 

     public ArrayList<String> getArrayListConsumer() { 
      return this.arraylistAttach; 
     } 

     public ArrayList<String> getArrayListConsumerId() { 
      return this.arraylistAttachId; 
     } 

     public Filter getFilter() { 
      if (mFilter == null) { 
       mFilter = new SimpleFilter(); 
      } 
       return mFilter; 
     } 

     public int getCount() { 
      return unfilteredValues.size(); 
     } 

     private class SimpleFilter extends Filter { 
      @SuppressWarnings("unchecked") 
      @Override 
      protected FilterResults performFiltering(CharSequence prefix) { 

       FilterResults results = new FilterResults(); 
       String prefixString = null == prefix ? null : prefix.toString().toLowerCase(); 
       ArrayList<HashMap<String, String>> unfilteredValues; 

       if (null != prefixString && prefixString.length() > 0) { 
        synchronized (mData) { 
         unfilteredValues = (ArrayList<HashMap<String, String>>) mData.clone(); 
        } 

        for (int i = unfilteredValues.size() - 1; i >= 0; --i) { 
         HashMap<String, String> h = unfilteredValues.get(i); 

         String str = (String)h.get(from[0]).toString(); 
          if (!str.toLowerCase().startsWith(prefixString)) { 
           unfilteredValues.remove(i); 
          } 

        } 

        //Log.i(Constants.TAG, String.valueOf(unfilteredValues.size())); 
        results.values = unfilteredValues; 
        results.count = unfilteredValues.size(); 

       } else { 
        synchronized (mData) { 
         results.values = mData; 
         results.count = mData.size(); 
        } 
       } 
       return results; 
      } 

      @SuppressWarnings("unchecked") 
      @Override 
      protected void publishResults(CharSequence constraint, FilterResults results) { 
       //noinspection unchecked 
       unfilteredValues = (ArrayList<HashMap<String, String>>) results.values; 
       notifyDataSetChanged(); 

      } 
     } 

    } 
+1

목록보기를 확인하기로

HashMap<String, String> SavedData = new HashMap<String, String>(); 

다음, 는 고유 식별자를 지정합니다. 그래서 그것은 edittext의 어떤 값도 저장하지 않을 것입니다. 입력 된 데이터를 저장하기 위해 해시 맵 또는 다른 데이터에 데이터를 저장해야하며 다시로드 할 때 편집 텍스트에 값을 지정할 수 있습니다. –

+0

예를 들어 주시겠습니까? – lolliloop

+0

http://lalit3686.blogspot.in/2012/06/today-i-am-going-to-show-how-to-deal.html –

답변

0

hashMap을 classVariable로 사용하십시오. 태그

editTxt.setTag(IdNo); 

처럼 글고 당신이 그것을 스크롤 할 때 뷰를 다시로드

if(SavedData.containsKey(IdNo)) { 
    editTxt.setText(SavedData.get(IdNo).toString()); 

} 

editTxt.addTextChangedListener(new TextWatcher() { 

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

      public void afterTextChanged(Editable s) { 

       //Save your Changed Text to HashMap using tag of edittext 
       SavedData.add(editTxt.getTag(),s.toString()); 

      } 
      public void onTextChanged(CharSequence s, int start, int before, 
        int count) { 

      } 
     }); 
+0

작동하지 않습니다 :(내 SimpleAdapter와 관련이 있습니까? – lolliloop

+0

단순한 어댑터와 아무 관련이 없습니다.이 모든 것을 하나로 결합하여 작업을 완료해야합니다. –

관련 문제