如何动态地增加布局并知道用户单击了哪一个?

时间:2020-02-10 16:05:05

标签: java android android-layout

首先,对不起我的英语。

然后,我正在尝试使用android studio开发一个应用。我做得很好,谢谢stackoverflow!

但是现在我有一个问题。在我的应用程序中,当用户想要在主布局中使用新的布局时,需要创建新的布局(从原始布局开始)。 我要复制的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true"
    android:background="?android:attr/selectableItemBackground"> >

     <TextView android:id="@+id/text1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="text1">
     <TextView android:id="@+id/text2"
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content"
              android:layout_marginTop="30dp"
              android:text="text2"

</LinearLayout>

添加它并为Textviews设置数据后,用户可以单击它以查看更多信息(可能使用其他布局)。

但是问题是,我不知道如何放置全局Click Listener。并且知道添加的女巫布局被点击了。我尝试了很多事情,因为它没有用,有人可以帮我吗?

0 个答案:

没有答案
相关问题