2013-06-29 4 views
0

커서 어댑터에서 기본 어댑터로 전환 중입니다. 그래서 난 내 CursorAdapter 클래스Android CursorAdapter 목록보기 채우기가 없습니다

public class OrderListAdapterCursor extends CursorAdapter{ 
private GetInventoryColor getInvColor = new GetInventoryColor(); 

public OrderListAdapterCursor(Context context, Cursor c, String x) { 
    super(context, c); 
    // TODO Auto-generated constructor stub 
} 


@Override 
public void bindView(View vi, final Context context, Cursor cursor) { 
    // TODO Auto-generated method stub 
    final ViewHolder holder = new ViewHolder(); 
    holder.thumb_image =(ImageView)vi.findViewById(R.id.ivOrderPicture); // thumb image 
    holder.tvmainOrder= (TextView)vi.findViewById(R.id.tvMainOrder); // titleOrder 
    holder.tvPrice = (TextView)vi.findViewById(R.id.tvOrderPrice); // price 
    holder.tvItemID = (TextView)vi.findViewById(R.id.tvItemID); // itemID 
    holder.tvItemCode = (TextView)vi.findViewById(R.id.tvItemCode); // item Code 

    holder.myLinearLayout = (LinearLayout) vi.findViewById(R.id.myLinearLayout); 
    holder.mylinearForRed = (LinearLayout)vi.findViewById(R.id.mylinearForRed); 
    holder.btnQuantity = (TextView)vi.findViewById(R.id.tvQuantity); 

    holder.tvmainOrder.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(0)))); 
     //tvmainOrder.setTypeface(modGen.typeFaceArial); 
    holder.tvItemID.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2)))); 
     //tvItemID.setTypeface(modGen.typeFaceArial); 
    holder.tvItemCode.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1)))); 
     //tvItemCode.setTypeface(modGen.typeFaceArial); 
    holder.tvPrice.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(3)))); 
    holder.btnQuantity.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(4)))); 

     //btnQuantity.setTag(position); 
     //btnInfo.setTag(position); 

    holder.thumb_image.setTag(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2)))); 
    holder.thumb_image.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       Object as = holder.thumb_image.getTag(); 
       final Integer myPosition = Integer.valueOf(as.toString()); 
       Toast.makeText(context, ""+myPosition, Toast.LENGTH_LONG).show(); 
       //String myItemID = data.get(myPosition).orderitemID; 
       //((TransactionPage) mainContext).ShowProductCatalogItem(myItemID, "0"); 
      } 
     }); 

     // String background = data.get(position).orderColor; 
     String background = getInvColor.getItemIDColor(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2))), context); 

     if (background.equalsIgnoreCase("RED")){ 
      holder.myLinearLayout.setBackgroundColor(Color.RED); 
     } 
     else if (background.equalsIgnoreCase("YELLOW")){ 
      holder.myLinearLayout.setBackgroundColor(Color.YELLOW); 
     } 
     else 
     { 
      holder.myLinearLayout.setBackgroundColor(Color.GREEN); 
     } 


     //tvStocksQty.setText(data.get(position).stocksQty); 
     LinearLayout mylinearForRed = (LinearLayout)vi.findViewById(R.id.mylinearForRed); 
     String qty1 = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(4))); 

      if (qty1 == null ||qty1.equalsIgnoreCase("")){ 
       mylinearForRed.setVisibility(View.INVISIBLE); 
       //int resmyID =R.drawable.ribbutton_counter; 
       //mylinearForRed.setBackgroundResource(resmyID); 
      }else{ 
       mylinearForRed.setVisibility(View.VISIBLE); 
       //int resmyID =R.drawable.ribbutton_counter; 
       //mylinearForRed.setBackgroundResource(resmyID); 
      } 

} 

@Override 
public View newView(Context context, Cursor cursor, ViewGroup parent) { 
    LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 
    View retView = inflater.inflate(R.layout.order_list_style, parent, false); 
    return retView; 
} 

    static class ViewHolder 
    { 
     public ImageView thumb_image; 
     public TextView tvmainOrder; 
     public TextView tvPrice; 
     public TextView tvItemID; 
     public TextView tvItemCode; 
     public TextView btnQuantity; 
     public LinearLayout myLinearLayout; 
     public LinearLayout mylinearForRed; 
    } 

    } 

그리고이 커서 어댑터에 새로운 오전으로이 코드와

selectQuery = "SELECT item_tb.dDesc, item_tb.itemcode, item_tb.ID as _id, price_tb.dPrice, transaction_tb.qtyOrdered FROM item_tb " + 
       "INNER JOIN price_tb ON item_tb.ID = price_tb.itemID " + 
       "INNER JOIN category_tb ON category_tb.ID = item_tb.categoryID " + 
       "LEFT JOIN transaction_tb ON item_tb.ID = transaction_tb.itemID " + 
       "WHERE category_tb.dDesc LIKE '"+ category +"%' " + 
       "AND (item_tb.dDesc LIKE '%" + sort +"%' OR " + 
       "item_tb.itemCode LIKE '" + sort + "%') " + 
       "AND item_tb.isPublish = '1'" + 
       "ORDER BY item_tb.dDesc ASC"; 

    mySQLiteAdapter = new SQLiteAdapter(context); 
    mySQLiteAdapter.openToRead(); 

    final Cursor cursor =mySQLiteAdapter.read(selectQuery); 

    //new Handler().post(new Runnable() { 
    // public void run() { 

      orderlistcursor= new OrderListAdapterCursor(context, cursor, sort); 
      listViewSearchPanel.setAdapter(orderlistcursor); 
      cursor.close(); 
      mySQLiteAdapter.close(); 

죄송 쿼리를 사용하여 바인딩을 만들었습니다. 900 + 데이터로 구성된 기본 어댑터를 사용하기 때문에 커서에 데이터가 있다고 확신합니다. 내 질문은 왜 그 listview isnt 바인딩입니다.

내가 놓친 것이 있습니까?

고마워요

+1

커서를 할당 한 후 닫은 것을 보면 문제가있을 수 있습니까? – DevZer0

+0

w8 sir은 – Androyds

+0

@ DevZer0가 작동하는지 확인하겠습니다.하지만 선생님은 커서를 바로 닫아야 만합니까? – Androyds

답변

2

귀하의 문제는 나중에 단계에서 커서를 파괴하여 어댑터에 할당 직후 cursor,

orderlistcursor= new OrderListAdapterCursor(context, cursor, sort); 
listViewSearchPanel.setAdapter(orderlistcursor); 
cursor.close(); 
mySQLiteAdapter.close(); 

을 닫기 때문이다 onces를 A onDestroy() 방법, 그것을 사용하여 수행.

+0

예전에 문제가 있습니다. – Androyds

4

setAdapter 다음에 커서를 닫지 마십시오. 커서를 Activity의 멤버 변수로 만들고 Activity의 onDestroy() 메서드로 커서를 닫습니다.