xml文件代码部分
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" > <EditText android:id="@+id/Phonenum" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入手机号码" /> <EditText android:id="@+id/duanxin" android:layout_width="match_parent" android:layout_height="200px" android:hint="请输入要发送的短信" android:layout_below="@id/Phonenum" /> <Button android:id="@+id/fasong" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送" android:layout_below="@id/duanxin" android:layout_alignParentRight="true" /> </RelativeLayout>
public class MainActivity extends Activity { private EditText phonenum,duanxin; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); phonenum=(EditText)findViewById(R.id.Phonenum); duanxin=(EditText)findViewById(R.id.duanxin); button=(Button)findViewById(R.id.fasong); ButLis lis=new ButLis(); button.setOnClickListener(lis); } class ButLis implements OnClickListener{ @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub String num=phonenum.getText().toString(); SmsManager sms=SmsManager.getDefault(); sms.sendTextMessage(num, null, duanxin.getText().toString(), null, null); } }).start(); } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。