jafeena_thaha
jafeena_thaha

Reputation: 15

Custom button click not working in android

I made a custom button control in android with one left image, right arrow image and textview in middle. I want to make the right arrow image in the button down arrow while clicking it. For that i had written the following in custom button class

public class ButtonWithTwoImagesAndOneText extends LinearLayout{
private ImageView _image, _arrow;
private TextView _text;
private View _viewupper, _viewlower, _viewlowersmall;

public ButtonWithTwoImagesAndOneText(Context context,AttributeSet attrs) {
    super(context, attrs, 0);
    Init(context);  


    RelativeLayout nameLayout= (RelativeLayout)findViewById(R.id.lytcontrollayout);
    nameLayout.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
                _arrow.setImageDrawable(getResources().getDrawable(R.drawable.arrowdown));
        }
    });
}

I used this button control in a layout like this.

<com.example.Controls.ButtonWithTwoImagesAndOneText
        android:id="@+id/btnaccountsettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        </com.example.Controls.ButtonWithTwoImagesAndOneText>

and in the class of that layout i added button click for btnaccountsettings.

btnAccountSettings.setOnClickListener(new RelativeLayout.OnClickListener() {            
        @Override
        public void onClick(View arg0) {
            Toast.makeText(Settings.this, "Account Settings", Toast.LENGTH_SHORT).show();
        }
    });

Now while running the app the arrow down is happening, but the toast is not working. Please help to solve this.

Upvotes: 0

Views: 216

Answers (1)

user3629714
user3629714

Reputation:

RelativeLayout.OnClickListener should be View.OnClickListener.

btnAccountSettings.setOnClickListener(new View.OnClickListener() {            
        @Override
        public void onClick(View arg0) {
            Toast.makeText(Settings.this, "Account Settings", Toast.LENGTH_SHORT).show();
        }
    });

Upvotes: 1

Related Questions