2017-07-01 27 views
0

私はこのコードを使用してアドレスを取得します。代わりにEditTextを使用する方法オートコンプリート用のフラグメント?

フィールドとしてEditTextのような単純な要素を使用し、フラグメントは使用しません。手段、私はのEditTextをクリックした場合

の下に、私は2つのフィールド(フィールド1アドレスのホーム、一例として、住所オフィス用フィールド2)を必要とするように、オートコンプリートのポップアップウィンドウが、呼ばれるべき

私は、コードを変更する必要があり

txt_lat = (TextView) findViewById(R.id.txt_lat); 
    txt_lon = (TextView) findViewById(R.id.txt_lon); 
    editText = (EditText) findViewById(R.id.editText1); 

    progressBar = (ProgressBar) findViewById(R.id.progressBar_anno_add_adress); 



    mGoogleApiClient = new GoogleApiClient 
      .Builder(this) 
      .addApi(Places.GEO_DATA_API) 
      .addApi(Places.PLACE_DETECTION_API) 
      .enableAutoManage(this, this) 
      .build(); 


    final PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) 
      getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); 





    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { 

     @Override 
     public void onPlaceSelected(Place place) { 
      // TODO: Get info about the selected place. 
      progressBar.setVisibility(View.VISIBLE); 
      Log.i("TAG", "Place: " + place.getName()); 
      LatLng latLng = place.getLatLng(); 

      txt_lat.setText(String.valueOf(latLng.latitude)); 
      txt_lon.setText(String.valueOf(latLng.longitude)); 
      editText.setText(place.getName()); 

      progressBar.setVisibility(View.GONE); 

      loc_lat=String.valueOf(latLng.latitude); 
      loc_lon=String.valueOf(latLng.longitude); 
      loc_adress=place.getName().toString(); 
     } 

     @Override 
     public void onError(Status status) { 
      // TODO: Handle the error. 
      Log.i("TAG", "An error occurred: " + status); 
     } 
    }); 

} 

@Override 
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 

} 

enter image description here

私はEditTextsを使いたいので、(私は、TextFieldを必要としません。

答えて

0

おそらくオートコンプリートの唯一の検索アイコンを必要とするあなたは今までAutoCompleteTextViewの代わりに、通常のEditTextを試してみました

Android Documentation

関連する問題