喜在片段我要挑从通讯录中的电话号码,并嵌入成的EditText使用onActivityResult在片段
,但它不是在片段工作,我用它的活性和它的作品。请你能帮助我,我应该如何改变它<感谢
public class Encrypt extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.encrypt, null);
phoneNumberDisplay = (EditText) v.findViewById(R.id.editTextPhoneNumber);
contactsButton=(Button)v.findViewById(R.id.buttonContacts);
contactsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(v==contactsButton){
Intent intent=new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, 1);
}
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri ur = data.getData();
Cursor c = managedQuery(ur, null, null, null, null);
if (c.moveToFirst()) {
String s = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
phoneNumberDisplay.setText(s);
}
}
}
return v;
}
错误:RESULT_OK不能被解析为一个变量
的方法managedQuery(URI,NULL,NULL,NULL,NULL)是不确定的键入新 View.OnClickListener(){}
看起来好,您是否尝试调试并检查是否已调用onActivityResult? –
@UdiOshi它不可能运行它强调onActivityResult和写:void是一个无效类型的变量onActivityResult – rgreso
@rgreso看到我的答案,它可能会解决您的问题。 – Synxis