如何对 Android 中的不同内容使用相同的 Activity?

How can I use the same Activity for different content in Android?

假设我正在为我的应用程序使用线性布局

 <TextView
    android:text="product 1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:textColor="@android:color/white"
    android:textSize="54sp"
    android:background="#009611" />

<TextView
    android:text="product 2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:textColor="@android:color/white"
    android:textSize="54sp"
    android:background="#123431" />

<TextView
    android:text="product 3"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:textColor="@android:color/white"
    android:textSize="54sp"
    android:background="#009688" />
</LinearLayout>

我的输出是:

当我 select product1 它应该打开 product1_des Activity
当我 select product2 它应该打开 product2_des Activity
当我 select product3 它应该打开 product3_des Activity
并继续..

我有 1000 个产品,我应该创建 1000 个 Activity? 我如何使用 product_des Activity(即单个 Activity)来支持我的所有 1000 种产品,这些产品具有与该产品相关的不同描述? 请帮助我。

And I have 1000 product should I create 1000 Activity? How can I use the product_des Activity (i.e single Activity) to support all my 1000 product with different description that is related to that product? Please help me.

没有!!!

您可以创建一个 Activity,例如 ProductDetail,但只有一个,然后您可以在任何想要显示产品详细信息的地方使用 putExtras()

Intent intent = new Intent(this, ProductDetail.class);
intent.putExtra("productName", ProductName);
startActivity(intent);

并且在 ProductDetail 中,您可以使用 Bundle

获取产品名称
Bundle b = new Bundle();
b = getIntent().getExtras();
String name = b.getString("productName");