我得到一个下面的编译时错误。我在那行的末尾提到了这个错误。
- 方法getTexttActivity(Intent)未定义类型 的EditText
- 对于类型,未定义toStringtActivity(Intent)方法 可编辑的
醇>
package com.implicitintent;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button read,call,msg;
EditText phone;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
read=(Button)findViewById(R.id.read);
read.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent read1=new Intent();
read1.setAction(android.content.Intent.ACTION_VIEW);
read1.setData(ContactsContract.Contacts.CONTENT_URI);
startActivity(read1);
}
});
phone=(EditText)findViewById(R.id.phone);
call=(Button)findViewById(R.id.call);
call.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent call1=new Intent();
call1.setAction(android.content.Intent.ACTION_CALL).setData(Uri.parse("tel:"+phone.getTexttActivity(call1))); ---->1st error
}
});
msg=(Button)findViewById(R.id.sms);
msg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent sms=new Intent();
sms.setAction(android.content.Intent.ACTION_VIEW);
sms.setData(Uri.parse("smsto:"+phone.getText().toStringtActivity(sms)));---->2nd Error
}
});
}
}
activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<Button
android:id="@+id/read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" View Contacts " />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/phone"
android:layout_width="150dip"
android:layout_height="wrap_content" />
<Button
android:id="@+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" call " />
<Button
android:id="@+id/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>
</LinearLayout>
任何人都可以帮助我。谢谢你。
答案 0 :(得分:0)
添加这一行(在你的情况下用电话改变call1)
EditText call1 = (EditText) findViewById(R.id.call1);
然后
当您想要获取文本时执行此操作
call1.getText().toString();
答案 1 :(得分:0)
它告诉你getTexttActivity(Intent)
类中没有这种方法EditText
。在onClick
监听器中用此替换您的代码。
try {
// set the data
String uri = "tel:" + phone.getText().toString();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
startActivity(callIntent);
} catch(Exception e) {
Toast.makeText(getApplicationContext(), "Your call has failed...", Toast.LENGTH_LONG).show();
e.printStackTrace();
}