我正在嘗試創建一個動態的android視圖。視圖的數量取決於列表中的項目。在Android視圖上下文類中設置實例變量
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginBottom="5px"
android:layout_marginTop="5px"
android:orientation="vertical"
android:padding="5dp" tools:context=".CategoryActivity">
<ImageView
android:id="@+id/img_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:foregroundGravity="center"
android:src="@android:drawable/ic_menu_view"/>
<TextView
android:id="@+id/text_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category"
android:textColor="#000000"
android:layout_alignParentStart="true"/></LinearLayout>
我膨脹此view
,然後添加到mainlayout
View view = getLayoutInflater().inflate(R.layout.activity_category_view, null);
mainLayout.addView(view)
上下文類爲視圖CategoryActivity
具有可變categoryId
我需要設置的值這categoryId
,並且是指一個實例它後來即onClick行動期間,然後採取適當的行動
在CategoryActivity類我已經正式提到
setContentView(R.layout.activity_category_view);
我已經想盡各種辦法,但仍無法解決和我卡住好!
訪問正是我一直在尋找..工作!謝謝 – Vivek