当我点击编辑文本中的按钮时,Android吐司文字

时间:2014-07-17 10:52:16

标签: android xml

当我点击编辑文字中的按钮时,我希望能够Toast Text

我的代码如下。

public class MainActivity extends ActionBarActivity {

private EditText input;
private Button click;

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

    input = (EditText) findViewById(R.id.editText1);
    click = (Button) findViewById(R.id.button1);

    click.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v){

        }
    });

}

3 个答案:

答案 0 :(得分:1)

尝试

Toast.makeText(getApplicationContext(), input.getText().toString, Toast.LENGTH_SHORT).show();

答案 1 :(得分:0)

click.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v){
        Toast.makeText(this, input.getText().toString, Toast.LENGTH_LONG).show();

        }
    });

简单:)

答案 2 :(得分:0)

private EditText input;

private Button click;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

input = (EditText) findViewById(R.id.editText1);

click = (Button) findViewById(R.id.button1);

click.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v){

Toast.makeText(getApplicationContext(), input.getText().toString, 

Toast.LENGTH_SHORT).show();
    }

});

}