2
如何将使用ButterKnife动态添加到父视图的布局内部的视图绑定。用Butterknife绑定以在android中动态添加视图
我有一个LinearLayout说容器。我有一个包含两个按钮自定义布局说这个布局childview 在活动我加入childview成功于母公司的LinearLayout 容器。
这是我的表现如何膨胀的自定义视图,并添加到LinearLayout中
bubbleView = inflater.inflate(R.layout.child, null);
systemChatLayoutContainer.addView(bubbleView);
现在我想结合存在的孩子布局 里面的按钮的意见,并添加执行某些操作时,按键目前里面的子布局。
这是在Button单击时动态添加到父容器的child.xml。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/btnCreateAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/btn_selector_green"
android:gravity="center"
android:padding="@dimen/_13sdp"
android:text="Create an account"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/white" />
<TextView
android:id="@+id/btnJstCheckingRate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/btn_selector_blue"
android:gravity="center"
android:padding="@dimen/_13sdp"
android:text="I'm just checking rates"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/white" />
<TextView
android:id="@+id/btnIhaveAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_btn_selector"
android:gravity="center"
android:padding="@dimen/_20sdp"
android:text="I've got an account"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/white" />
</LinearLayout>
是不是有办法实现@OnClick的ButterKnife到perferom动作? –
如果你愿意,你可以在这个视图中。如果这个解决方案有效,你可以请你提供答案。谢谢:) –
谢谢老板那段代码工作 –