在我的android应用程序中发送消息我已经使用了下面的代码。在android中发送消息
package wishme.code;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Activity2 extends Activity{
public void onCreate(Bundle savedInstancestate) {
super.onCreate(savedInstancestate);
setContentView(R.layout.main2);
Button previous=(Button) findViewById(R.id.button_prev);
Button send=(Button) findViewById(R.id.button_send);
EditText ph_no=(EditText) findViewById(R.id.edit_phone);
EditText msg=(EditText) findViewById(R.id.edit_msg);
}
public void prevclickhandler(View view)
{
switch(view.getId())
{
case R.id.button_prev:
Intent intent=new Intent();
setResult(RESULT_OK,intent);
finish();
break;
case R.id.button_send:
**String ph_no= ph_no.getText().tostring();**
}}
}
但行高亮提示错误是 的getText是未定义string类型 我怎样才能解决这个方法。
在一个侧面说明,你并不需要声明的如果你不打算修改它们,可以在'onCreate'中使用Button和EditText变量。系统在读取XML文件时(在'setContentView'期间)为您创建并设置它们。 'findViewById'函数只是引用已经存在的变量的一种方式。 – eternalmatt