0

https://itunes.apple.com/us/app/party-cupcake-recipes-300+/id572480130?mt=8

上記の例のようなアプリケーションを作りたいです。私はAndroidとJavaでそれをやっています。メインメニューにリストビューを使用しています。スープ、メインディッシュなどがあります。メニューの各項目のアクティビティを作成し、ユーザーがクリックすると、この新しいアクティビティが開きます。

たとえば、スープアクティビティには別のリストビューがあり、作成したスープのリストがあり、レシピはフォトショップで作成したイメージビューになり、テキストなどはありません。

ここでの問題は、おそらく 50 ~ 60 のレシピがあり、それらのそれぞれに対してクラスを作成するのは論理的に聞こえないことです。OOP ロジックでは、レシピなどのクラスを作成し、レシピの名前とそのイメージ ビューを持つオブジェクトを生成する必要があります。したがって、必要に応じて何百ものそれらを生成できます。これは論理的に聞こえます。リソースフォルダーにすべての写真を保存することを考えています。そうするとき、xmlファイルに追加せずに、画像へのリンクのみを与えることができます。つまり、レシピ オブジェクトで構成される Arraylist を使用してリストビューを実行できます。それらをクリックすると、そのイメージが開きます。それらすべてのxmlファイルがないと、それともまったく不可能ですか? すべての助けをいただければ幸いです...

4

1 に答える 1

0

「それらすべてのxmlファイル」とはどういう意味かわかりませんが、BitmapFactory.decodeResource(getResources()、R.drawable.pictureId)で画像を取得し、そのビットマップをImageViewで表示できます。

public class MySimpleArrayAdapter extends ArrayAdapter<MyImage> {
  private final Context context;
  private final ArrayList<MyImage> values;

  public MySimpleArrayAdapter(Context context, ArrayList<MyImage> values) {
    super(context, R.layout.rowlayout, values);
    this.context = context;
    this.values = values;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.label);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
    textView.setText(values.get(i).getDesc());
    imageView.setImageResource(values.get(position).getImageId());

    return rowView;
  }
} 

public class MyImage{
   String desc;
   int imageId;
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="22px"
        android:layout_height="22px"
        android:layout_marginLeft="4px"
        android:layout_marginRight="10px"
        android:layout_marginTop="4px" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20px" >
    </TextView>

</LinearLayout> 
于 2013-03-08T22:34:36.510 に答える