【发布时间】:2018-04-24 09:49:47
【问题描述】:
我在CardView 中有一个TextView。我希望在点击Textview 时发生一些功能,但我的android:onClick 没有响应点击,因为该方法没有被调用。问题是什么?请帮帮我。
这是我的代码:
XML
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Application info"
android:textAlignment="center"
android:layout_gravity="left"
android:layout_margin="10dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ApplicationHide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:orientation="vertical"
android:weightSum="11">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/occupation"
android:hint="Occupation" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:id="@+id/occupiSalaryHide"
android:layout_width="match_parent"
android:visibility="gone"
android:orientation="vertical"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/companyName"
android:layout_weight="1"
android:hint="Company name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/monthlyIncome"
android:layout_weight="1"
android:hint="Gross monthly income" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/modeSalary"
android:layout_weight="1"
android:hint="Mode of salary" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/typeCompany"
android:layout_weight="1"
android:hint="Type of Company*" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/professionType"
android:layout_weight="1"
android:hint="Profession Type" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/designation"
android:layout_weight="1"
android:hint="Designation" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/noYearCurrWork"
android:layout_weight="1"
android:hint="Number of Years in Current Work" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:inputType="none"
android:textIsSelectable="true"
android:maxLines="1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/noOfYears"
android:layout_weight="1"
android:hint="Total no. of years in work" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center">
<TextView
android:id="@+id/applicationContinu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button_border"
android:gravity="center"
android:clickable="true"
android:onClick="applicationValid"
android:padding="10dp"
android:text="Continue"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
我在这上面还有两个这样的,但在那,onClick() 正在工作,但在这方面不起作用。在这个setOnClickListener() 工作但我想使用android:onClick?
我是不是做错了什么?
【问题讨论】:
-
显示你的java代码。
-
你的问题是什么?我不明白你的问题。哪个 textview 点击事件不起作用?
-
嗨 Ankit,你对 android 来说似乎很新鲜。当您要求 onclick 方法时,您必须分享您的 java 代码以让其他人查看,这是什么问题。
-
对不起......我忘了为 TextView 添加该代码。现在是完整的代码
标签: android onclick textview cardview