How to catch a click event on a button?

前端 未结 7 942
[愿得一人]
[愿得一人] 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:16

    /src/com/example/MyClass.java

    package com.example
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    
    public class MyClass extends Activity
    {
    
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    
    
        Button button = (Button) findViewById(R.id.button1);
    
        button.setOnClickListener(new OnClickListener()
        {
          public void onClick(View v)
          {
             ImageView iv = (ImageView) findViewById(R.id.imageview1);
             iv.setVisibility(View.VISIBLE);
          }
        });
    
      }
    }
    

    /res/layout/main.xml

    
    
        

提交回复
热议问题