2011-12-08 28 views
0

我現在停留在一個點上,找不到任何解決方案。圖庫,sqlite android?

描述:我有具有表(信道表),其具有4列

uid  channel_name  cid(country id)  rating 

uid是唯一的信道ID的源碼數據庫。

我有星級,三個圖像,如果星是黃色然後信道有4或5個等級 如果星是半黃色然後信道等級爲2或3,如果星白色然後額定值1將被考慮。

我在android中顯示了這些來自圖庫小部件的三個圖像。 ant星形圖像下面的頻道名稱。根據頻道評級。

public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) { 
      View view = null; 
      Cursor mCursor=db.dataChannelsName(); 
      mCursor.moveToFirst(); 
      String [] channels_name = new String[mCursor.getCount()]; 
      for(int icount=0; icount<mCursor.getCount();icount++) { 
       channels_name[icount] = mCursor.getString(mCursor.getColumnIndex("name")); 
       mCursor.moveToNext(); 
      } 

      if(paramView == null) { 
        LayoutInflater inflater = LayoutInflater.from(mContext); 
        view = inflater.inflate(R.layout.items1, null); 
        ImageView image1 = (ImageView) view.findViewById(R.id.image1); 
        TextView description = (TextView) view.findViewById(R.id.description); 

        image1.setImageResource(mImageIds[paramInt]); 
        description.setTextColor(0xffffffff); 
        description.setText(channels_name[paramInt]); 
      } else { 
        view = paramView; 
      } 

      return view; 

問題1:

我將如何只顯示不同頻道名稱的所有通道這三種圖像。?

問題2:

它可以是可能在數據庫

同名通道我使用SQL查詢和光標用於檢索數據。

現在我的問題是,當用戶將從畫廊中選擇特定的頻道,然後有可能有多個同名的頻道。

我只想在用戶點擊畫廊中的頻道名稱時存儲uid?

編輯我剛剛解決了第二個問題,但我在問題1

任何幫助卡住,將不勝感激。

回答

1

讓我們開始修理一些東西吧?現在

public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) { 
    View view = null; 
    Cursor mCursor=db.dataChannelsName(); 
    mCursor.moveToFirst(); 
    String [] channels_name = new String[mCursor.getCount()]; 
    for(int icount=0; icount<mCursor.getCount();icount++) { 
     channels_name[icount] = mCursor.getString(mCursor.getColumnIndex("name")); 
     mCursor.moveToNext(); 
    } 

的getView函數是每次稱爲一個ListView顯示一個新行(即使滾動時!!)......我猜想db.dataChannelName()火災查詢SELECT * from channel(或更糟的是,你可能會被打開和關閉數據庫)....這是一個非常昂貴的操作,您應該在構造函數中查詢一次,將通道名稱數組存儲爲成員變量,並將其用於適配器的其餘部分。

這裏有一個簡潔的方式..

public View getView(int paramInt, View view, ViewGroup paramViewGroup) { 
    if(view== null) { 
     LayoutInflater inflater = LayoutInflater.from(mContext); 
     view = inflater.inflate(R.layout.items1, null); 
     } 

     ImageView image1 = (ImageView) view.findViewById(R.id.image1); 
     TextView description = (TextView) view.findViewById(R.id.description); 

     image1.setImageResource(mImageIds[paramInt]); // i'm assuming 0 - 0 star, 1 - 1 star, etc... 
     description.setTextColor(0xffffffff); 
     description.setText(channels_name[paramInt]); //remember channel_name was obtained in the constructor. 


return view 
} 
+0

你是對的。每次都會調用getView方法。順便說一下,我取消了這個設計,並使用不同的應用程序設計,並感謝您的時間。 –