2017-11-11 3 views
-1

CardView 안에 TextView이 있습니다. Textview 클릭시 일부 기능을 사용하고 싶지만 내 은 메서드가 호출되지 않아 클릭에 응답하지 않습니다. 이슈가 뭐야? 도와주세요, 제발. 나는 이와 위에 있지만 두 개를코드에서 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()에서 작동하지만 을 사용하고 싶습니까?

내가 잘못 했습니까?

+0

자바 코드를 보여줍니다. –

+0

당신의 문제는 무엇입니까? 나는 당신의 질문을 이해하지 못합니다. 어떤 textview 클릭 이벤트가 작동하지 않습니까? –

+0

안녕 Ankit 당신은 안드로이드에 매우 신선하게 보입니다. onclick 메서드를 요청할 때 다른 사람이 검토 할 수 있도록 Java 코드를 공유해야합니다. 문제점은 무엇입니까? – Khemraj

답변

0

어떤보기를 클릭하여 설정할 수 있습니다.

당신이 가진 가정 텍스트 뷰

<TextView 
    android:id="@+id/tv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Application info"/> 
당신이 다음

<TextView 
    android:id="@+id/tv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Application info" 
    android:onClick="yourMethodName..."/> 
같은 XML하여 메소드를 호출 할 수있는 활동을 사용하는 경우 당신은

public void setClick(){ 
    TextView textView = (TextView) findViewById(R.id.tv); 
    textView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
     //    ... your code for click 
     } 
    }); 
} 

처럼 자바 코드로 클릭하여 설정할 수 있습니다

xml 방식의 클릭은 액티비티에서만 작동합니다.

+0

이 코드 위에 비슷한 코드가 있고이 코드에서 onClick이 작동하지만 작동하지 않는 경우 동일한 액티비티입니다 ( –

+0

). 내가 설명한 해결책을 모두 사용할 수 있습니다. ID가 같은지 다시 확인하십시오. 당신이 XML을 가져 가면서. – Khemraj

+0

@AnkitSrivastava는 onclick에 대한 자바 코드를 공유합니다. – Khemraj

관련 문제