2011-11-12 3 views
0

다음 사용자 지정 어댑터를 사용하여 DB 커서에서 내 목록 컨트롤을 채 웁니다. super가 호출 될 때 특별히이 코드가 생성자에서 충돌하는 이유를 이해할 수 없습니다.DB 커서가있는 사용자 지정 어댑터의 쿼리

public class ListAdaptor extends SimpleCursorAdapter { 

    private Cursor dataCursor; 
    private LayoutInflater mInflater; 

    class ViewHolder { 

     public TextView label = null; 
     public CheckBox chkBx = null; 
     public TextView price = null; 
     public TextView weight = null; 
    } 


    //constructor 
    public ListAdaptor(Context context, int layout, Cursor dataCursor, String[] from, int[] to) { 

     super(context, layout, dataCursor, from, to); 
     this.dataCursor = dataCursor; 
     mInflater = LayoutInflater.from(context); 
    } 

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

     // A ViewHolder keeps references to children views to avoid unneccessary calls 
     // to findViewById() on each row. 
     ViewHolder holder; 

     // When convertView is not null, we can reuse it directly, there is no need 
     // to reinflate it. We only inflate a new View when the convertView supplied 
     // by ListView is null. 

     if (convertView == null) { 

      // Inflate the view 
      convertView = mInflater.inflate(R.layout.listviewlyt, null); 

      // Get the ID's of the views 
      TextView tmpLbl  = (TextView)convertView.findViewById(R.id.label); 
      CheckBox tmpChkBx = (CheckBox)convertView.findViewById(R.id.chkbox); 
      TextView tmpPrc  = (TextView)convertView.findViewById(R.id.labelPrice); 
      TextView tmpWt  = (TextView)convertView.findViewById(R.id.labelWt); 


      // Creates a ViewHolder and store references to the two children views 
      // we want to bind data to. 
      holder = new ViewHolder(); 

      holder.label = tmpLbl; 
      holder.chkBx = tmpChkBx; 
      holder.price = tmpPrc; 
      holder.weight = tmpWt; 

      // Set the Tag 
      convertView.setTag(holder); 

     } 
     else { 
      // Get the ViewHolder back to get fast access to the TextView 
      // and the ImageView. 
      holder = (ViewHolder) convertView.getTag(); 
     } 

     // Bind the data efficiently with the holder. 
     // Cursor to current item 

     dataCursor.moveToPosition(position); 
     String keyWrd = dataCursor.getString(2); 
     String price = dataCursor.getString(3); 

     TextView labelRef = holder.label; 
     CheckBox chbxRef = holder.chkBx; 
     TextView labelPrc = holder.price; 
     TextView labelWt = holder.weight; 

     labelRef.setText(keyWrd); 
     labelPrc.setText(price); 
     //chbxRef.setChecked(refObj.flag); 
     //labelWt.setText(refObj.wt); 

     return convertView; 
    } 
} 

누군가가 이유를 찾도록 도와 줄 수 있습니까?

+0

후 오류 로그주세요. – hovanessyan

+0

스레드 [<3> 본체 (일시 중지) \t \t \t \t ActivityThread.performLaunchActivity (ActivityThread $ ActivityRecord 의도) 라인 : 2,494 \t \t \t \t ActivityThread.handleLaunchActivity (ActivityThread $ ActivityRecord 의도) 라인 : 2,512 \t \t \t \t ActivityThread.access $ 2200 (ActivityThread, ActivityThread $ ActivityRecord, Intent) 줄 : 119 \t \t \t \t ActivityThread $ H.handleMessage (메시지) 줄 : 1863,210 \t \t \t ActivityThread $ H (핸들러) .dispatchMessage (메시지) 라인 99 \t \t \t \t Looper.loop() 선 123 \t \t \t \t ActivityThread.main (문자열 []) 라인 : 4363 – Phoenix

+0

무엇 예외는 무엇입니까? –

답변

0

대부분의 아마이 행이 제공 될 수있는 문제

mInflater = LayoutInflater.from(context); 
+0

감사합니다. 나는 이것을 알아 냈다. 문제는 커서가 작동하지 않아 DB에서 _Id를 사용하지 않고 있다는 것이 었습니다. 또한 CusrorAdaptor에서 어댑터 클래스를 확장하고 BindView 및 NewView 멤버 함수를 재정의하는 것이 더 쉽다는 것을 발견했습니다. – Phoenix

관련 문제