2011-12-08 12 views
0

私は現在、ある時点で立ち往生しており、解決策を見つけることができません。ギャラリー、sqlite android?

説明:私は

uid  channel_name  cid(country id)  rating 

UIDは固有のチャネルIDは4列を有するSQLiteのデータベーステーブル(チャネル・テーブル)を有するを有します。

星が黄色の場合、チャンネルは4または5のいずれかの評価をします 星が半黄色の場合はチャンネルの評価が2または3です。星が白である場合は、評価1が考慮されます。

私はこれらの3つの画像をギャラリーウィジェットからアンドロイドで表示しています。スター画像の下のチャンネル名。チャンネルの評価に従って。

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を保存したいですか?

EDIT私はちょうど2番目の質問を解決するが、私は任意の助けをいただければ幸いです質問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メソッドの機能は、リストビューは、あなたが開閉される可能性があります...私は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メソッドは毎回呼び出されます。ところで、私はこのデザインをキャンセルし、あなたの時間のためにアプリと感謝のために別のデザインを使用しています。 –