2014-09-04 6 views
0

이 질문은 여러 번 물어 볼 수는 있지만 문제를 해결할 수는 없습니다. 사용자 지정 ListView 데이터를 스크롤 할 때마다 위치가 잘못 배치 된 경우 Where else 조건. 제 실수를 알려주십시오.스크롤 할 때 ListView 데이터 위치가 잘못됨

공용 클래스 ImageAdapter를 사용하면 뷰를 만들 때 getItem()에 첫 번째 호출에 전달 된 position에 결합 setOnClickListener에 의해 할당 청취자 내부 BaseAdapter {

private LayoutInflater mInflater; 

public ImageAdapter(Context c) { 
    mInflater = LayoutInflater.from(c); 

} 

@Override 
public Object getItem(int position) { 
    return null; 
} 

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

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    final ViewHolder holder; 



    if (convertView == null) { 
     convertView = mInflater.inflate(R.layout.griddata, null); 
     k = position; 
     holder = new ViewHolder(); 
     holder.txttitle = (TextView) convertView 
       .findViewById(R.id.txttitle); 
     holder.txtproduct = (TextView) convertView 
       .findViewById(R.id.txtproduct); 
     holder.txtcustname = (TextView) convertView 
       .findViewById(R.id.txtcustname); 
     holder.txtcompanyname = (TextView) convertView 
       .findViewById(R.id.txtcompanyname); 
     holder.txtaddress = (TextView) convertView 
       .findViewById(R.id.txtaddress); 
     holder.txttime = (TextView) convertView 
       .findViewById(R.id.txttime); 
     holder.txtrefid = (TextView)convertView.findViewById(R.id.txtrefid); 
     holder.btnphoto1 = (Button)convertView.findViewById(R.id.btnphoto1); 
     holder.btnphoto2 = (Button)convertView.findViewById(R.id.btnphoto2); 
     holder.btnsignpad = (Button)convertView.findViewById(R.id.btnsignature); 

     if (imgurl1list.get(position).equals("anyType{}")) { 
      holder.btnphoto1.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        i = 1; 
        type = title.get(position).toString(); 

        refid = v.getTag().toString(); 
        selectedbutton = holder.btnphoto1; 

        selectImage(); 

       } 
      }); 
     } 
     else{ 
      holder.btnphoto1.setText("Photo Exists"); 
     } 


     if (imgurl2list.get(position).equals("anyType{}")) { 
      holder.btnphoto2.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        i = 2; 
        type = title.get(position).toString(); 
        refid = v.getTag().toString(); 
        selectedbutton = holder.btnphoto2; 
        selectImage(); 
       } 
      }); 
     } 
     else{ 
      holder.btnphoto2.setText("Photo Exists"); 
     } 
     if (imgurl3list.get(position).equals("anyType{}")) { 
      holder.btnsignpad.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        type = title.get(position).toString(); 
        refid = v.getTag().toString(); 
        selectedbutton = holder.btnsignpad; 
        signpadselection(); 
       } 
      });  
     } 
     else{ 
      holder.btnsignpad.setText("Signature Exists"); 
     } 

     convertView.setTag(holder); 
    } 

    else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 


    holder.txttitle.setText(title.get(position)); 
    holder.txtrefid.setText(uniquerefid.get(position)); 
    holder.txttitle.setTag(uniquerefid.get(position)); 
    holder.txtaddress.setText(address.get(position)); 
    holder.txtcustname.setText(customername.get(position)); 
    holder.txtcompanyname.setText(companyname.get(position)); 
    holder.txtproduct.setText(product.get(position)); 
    holder.txttime.setText(createdon.get(position)); 
    holder.btnphoto1.setTag(uniquerefid.get(position)); 
    holder.btnphoto2.setTag(uniquerefid.get(position)); 
    holder.btnsignpad.setTag(uniquerefid.get(position)); 




    return convertView; 
} 

class ViewHolder { 
    TextView txttitle, txtcompanyname, txtproduct, txtcustname, 
      txtaddress, txttime, txtrefid; 
    Button btnphoto1, btnphoto2, btnsignpad; 

} 

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return title.size(); 
} 

}

답변

0

을 확장합니다. 스크롤을 걸 때도 position이 그대로 남아 있습니다. 이 아니기 때문에,

holder.position = position; 

을 그리고

title.get(position).toString(); 

title.get(holder.position).toString(); 

는 당신이 변경된 모든 데이터를 확인하려면 변경 position 매개 변수에서 final 한정자를 제거 : 당신은 대신 holder에 저장한다 더 이상 필요 없습니다.

또한 getItemId()에서 0을 반환하는 것은 좋지 않습니다 (스크롤에 영향을 미치지는 모르겠지만 다른 것들에도 영향을 미칩니다). 대신 position을 반품하는 것이 좋습니다.

+0

답변 해 주셔서 감사합니다. 그러나 didnt 일 : ( –

+0

@MayuriRuparel 당신은 업데이트 된 코드를 게시 할 수 있습니까? –

관련 문제