How to catch a click event on a button?

前端 未结 7 896
[愿得一人]
[愿得一人] 2020-12-05 04:28

.NET Developer here just getting started with Eclipse and Android.

Can someone show me in the simplest way possible, with the absolute fewest lines of code, how to D

7条回答
  •  失恋的感觉
    2020-12-05 05:12

    Just declare a method,e.g:if ur button id is button1 then,

    button1.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(Context, "Hello", Toast.LENGTH_SHORT).show();
            }
        });
    

    If you want to make the imageview1 visible then in that method write:

    imageview1.setVisibility(ImageView.VISIBLE);
    

提交回复
热议问题