MainActivity.java
package com.example.widgetall;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.content.Intent;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
find_and_modify_button();
}
private void find_and_modify_button(){
Button edit_view_button=(Button)findViewById(R.id.edit_view_button);
edit_view_button.setOnClickListener(edit_view_button_listener);
}
private Button.OnClickListener edit_view_button_listener=new Button.OnClickListener(){
public void onClick(View v){
Intent intent=new Intent();
intent.setClass(MainActivity.this, EditTextActivity.class);
startActivity(intent);
}
};
}
EditTextActivity.java
package com.example.widgetall;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
public class EditTextActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("EditView Activity");
setContentView(R.layout.editview);
find_and_modify_editview();
}
private void find_and_modify_editview(){
Button get_edit_view_button=(Button)findViewById(R.id.get_edit_view_button);
get_edit_view_button.setOnClickListener(get_edit_view_button_listener);
}
private Button.OnClickListener get_edit_view_button_listener=new Button.OnClickListener(){
public void onClick(View v){
EditText edit_text=(EditText)findViewById(R.id.edit_text);
CharSequence edit_text_value=edit_text.getText();
setTitle("Edit的值:"+edit_text_value);
}
};
}