Skip to content Skip to sidebar Skip to footer

Android Onclick Action

Fellas, I've been scratching my head trying to implement a fairly simple onClick action on a TextView to no success. Here is my code: public class AccountsActivity extends Acti

Solution 1:

Add android:clickable="true" for TextView in xml

and as @ Altaf mentioned in his answer, remove the listener. Just have,

publicvoidperformClick(View view){
     Log.i("Action::", "clicked!!");

              // custom dialogfinalDialogdialog=newDialog(context);
     dialog.setContentView(R.layout.custom_dialog);
     dialog.setTitle("This is a custom dialog");

     dialog.show();
 }

Or alternate way is to remove the android:onClick="onClick" and implement the onClickListener for the TextView in your activity.

Solution 2:

Remove listener

tvNextOkin.setOnClickListener(newOnClickListener() {}

You just need performClick method

Solution 3:

you should register your onClick listener in onCreate(). You can reference Android SDK document.

Solution 4:

Add this in your xml for textview

android:onClick="onClick"android:clickable="true"

and perfrom onclick operation

publicvoidonClick(View v) {
        ...
      }  

Solution 5:

I saw your problem.

When you set android:onClick="performClick", It mean, when user click to TextView the method performClick will be invoked.

In this method will do: SET onClickListener for tvNextOkin

It doesn't show any dialog. :D

The solution:

<TextView
      android:id="@+id/tv_acc_next_of_kin"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="5dp"
      android:text="tap here to add"
      android:textColor="#000"
      android:textSize="14dp"
      android:typeface="sans" />

tvNextOkin.setOnClickListener(newOnClickListener() {

             @OverridepublicvoidonClick(View arg0) {

                  // custom dialogfinalDialogdialog=newDialog(context);
                dialog.setContentView(R.layout.custom_dialog);
                  dialog.setTitle("This is a custom dialog");

                     dialog.show();
}

Do not put it in performClick method.

Hope this will help you.

Regards,

Post a Comment for "Android Onclick Action"