Hi in the fragment I want to select a phone number from contacts and paste it into an EditText
but it doesn’t work in the fragment, I use it in action, and it works. Please, could you help me, how can I change this? thank
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 cannot be resolved by a variable
The managedQuery method (Uri, null, null, null, null) is undefined for the type new View.OnClickListener () {}
source
share