0

ユーザーが飲酒ゲームの王様をプレイできるAndroidアプリを作成しています。ランダムに選択された配列「カード」にすべての @drawable 画像があります。レイアウトを作成したり、トーストを 1 つの画像だけに設定したりせずに、トーストに画像を表示する方法がわかりません。

これが私がこれまでに得たものです...

配列:

final int [] cards = {R.drawable.twoofdiamonds, R.drawable.threeofdiamonds, R.drawable.fourofdiamonds, R.drawable.fiveofdiamonds, R.drawable.sixofdiamonds,
          R.drawable.sevenofdiamonds, R.drawable.eightofdiamonds, R.drawable.nineofdiamonds, R.drawable.tenofdiamonds, R.drawable.jofdiamonds, R.drawable.qofdiamonds,
          R.drawable.kofdiamonds, R.drawable.aceofdiamonds, R.drawable.twoofclubs, R.drawable.threeofclubs, R.drawable.fourofclubs, R.drawable.fiveofclubs,
          R.drawable.sixofclubs, R.drawable.sevenofclubs, R.drawable.eightofclubs, R.drawable.nineofclubs, R.drawable.tenofclubs, R.drawable.jofclubs,
          R.drawable.qofclubs, R.drawable.kofclubs, R.drawable.aceofclubs, R.drawable.twoofhearts, R.drawable.threeofhearts, R.drawable.fourofhearts,
          R.drawable.fiveofhearts, R.drawable.sixofhearts, R.drawable.sevenofhearts, R.drawable.eightofhearts, R.drawable.nineofhearts, R.drawable.tenofhearts, R.drawable.jofhearts,
          R.drawable.qofhearts, R.drawable.kofhearts, R.drawable.aceofhearts, R.drawable.twoofspades, R.drawable.threeofspades, R.drawable.fourofspades,
          R.drawable.fiveofspades, R.drawable.sixofspades, R.drawable.sevenofspades, R.drawable.eightofspades, R.drawable.ninefspades, R.drawable.tenofspades,
          R.drawable.jofspades, R.drawable.qofspades, R.drawable.kofspades, R.drawable.aceofspades};

画像トーストで行った試み:

Toast ImageToast = new Toast(getBaseContext());
        LinearLayout toastLayout = new LinearLayout(getBaseContext());
        toastLayout.setOrientation(LinearLayout.HORIZONTAL);
        ImageView image = new ImageView(getBaseContext());
        TextView text = new TextView(getBaseContext());

        image.setImageResource(R.drawable.cards[randomSequence[cardCount]]); //error here

        text.setText("Hello!");
        toastLayout.addView(image);
        toastLayout.addView(text);
        ImageToast.setView(toastLayout);
        ImageToast.setDuration(Toast.LENGTH_LONG);
        ImageToast.show();

どんな助けでも歓迎します、私はこれに初心者です。乾杯。

4

1 に答える 1