android实验一之helloandroid

实验结果:


代码:


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends Activity {
private Button btnClick;
private EditText etName;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


btnClick = (Button) findViewById(R.id.btnClick);
btnClick.setOnClickListener(new ClickHandler());


etName = (EditText) findViewById(R.id.etName);


}


class ClickHandler implements OnClickListener {




@Override
public void onClick(View view) {
String name = etName.getText().toString();
Toast.makeText(MainActivity.this, "Hello " + name + " !",
Toast.LENGTH_LONG).show();



}
}


}



展开阅读全文

没有更多推荐了,返回首页