2017-09-13 3 views

答えて

0

あなたはEDITTEXTを介してこれを達成することはできません、あなたが許可に

を追加する必要があり、あなたのマニフェストでのonCreate

AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView); 

    String selectedEmail; 
    List<String> emails = new ArrayList<>(); 
    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ 
    //get runtime permission 

    Account[] accounts = AccountManager.get(YourActivityName.this).getAccounts(); 

    int i=0; 
    for (Account account : accounts) { 
     if (emailPattern.matcher(account.name).matches()) { 
      String possibleEmail = account.name+"\n"; 
      emails.add(possibleEmail); 
     } 
    } 

    ArrayAdapter<String> adapter = new ArrayAdapter<String> 
    (this,android.R.layout.simple_list_item_1,emails); 
    autoComplete.setAdapter(adapter); 

    //default selected email 
    selectedEmail = emails.get(0); 
    autoComplete.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
      // You can get the user selected email here  
      String selectedEmail = emails.get(position) 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> parent) { 

     } 
    }); 

であなたの活動ファイルにAutoCompleteTextView

<AutoCompleteTextView 
android:id="@+id/autoCompleteTextView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
> 

を使用する必要があります

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 

API> = 23(Marshmallow)の場合は、実行時アクセス権も取得する必要があります。ランタイム権限

https://developer.android.com/training/permissions/requesting.html

+0

のためにこれをフォローしますが、この@ykbを試したのですか? –

+0

いいえ@Shriyansh Gautam未だに。 – ykb

+0

何かエラーが表示されている場合は、私に教えてください –

関連する問題