-1

SimpleCursorAdapter を使用して SQLite データベースからデータを取得し、カスタム レイアウトとリストビューを使用してデータベースから 2 つの文字列を表示しています。今、私は2つの質問があります:

  1. 特定の条件に基づいて特定の行に星を表示したい場合、カスタム アダプターを作成する必要がありますか? カスタム レイアウトで既に画像を非表示に設定しており、行データ自体の条件に基づいて表示に設定したいと考えています。すべてのタブとお気に入りタブを実装しましたが、すべて正常に動作し、星のアイコンが必要でした。レシピ画像を特定の行に配置することでも、この問題に直面します。

  2. リストビューで画像を動的に取得する最良の方法は何ですか? 怠惰な画像のチュートリアルに従いましたが、baseadapter を使用して実装されたため、CustomCursorAdapter を使用して実装する方法がわかりませんでした。simplecursor チュートリアルを使用した画像の遅延読み込みへのリンクは何ですか?

 

public class AlternateRowCursorAdapter extends SimpleCursorAdapter{
    int layoutn;
    Cursor mCursor;
    String[] fromn;
    int[] ton;

    LayoutInflater mInflater;

    private int[] colors = new int[] { Color.parseColor("#000000"), Color.parseColor("#303030") };

    public AlternateRowCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
        super(context, R.layout.listtype, c, from, to);
        this.mCursor = c;
    }

    /**
     * Display rows in alternating colors
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = super.getView(position, convertView, parent);

        ImageView star = (ImageView)view.findViewById(R.id.favoritesicon); // The star I want to show

        if (mCursor.getString(8) == "YES") // shows if the item is in favorites
        {
            star.setVisibility(view.VISIBLE);
        }

        int colorPos = position % colors.length;
        view.setBackgroundColor(colors[colorPos]);

        return view;
    }
}
4

1 に答える 1

1

カスタムアダプタを作成する必要がありますか?

はい、カスタムアダプターを作成し、行にスターを追加する必要があります。

リストビューで画像を動的に取得するための最良の方法は何ですか?

ユニバーサルイメージローダーを使うべきだと思います。Android用のGitHubプロジェクトUniversalImageLoaderを参照してください。

于 2012-04-21T08:59:25.373 に答える