Android studio 地图中的PlaceAutoCompleteTextView

Android studio 地图中的PlaceAutoCompleteTextView,android-studio,Android Studio,我一直在尝试在我的2 AutoCompleteTextView中添加位置预测列表,我也在我的项目中实现了这一点,但现在我的仪表板活动在设置适配器时出错。设置适配器时的错误类型转换错误 activity\u dashboard.xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns

我一直在尝试在我的2 AutoCompleteTextView中添加位置预测列表,我也在我的项目中实现了这一点,但现在我的仪表板活动在设置适配器时出错。设置适配器时的错误类型转换错误

activity\u dashboard.xml

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:name="com.google.android.gms.maps.SupportMapFragment" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/map_marker"
                />
            <RelativeLayout
                android:id="@+id/pickupRL"
                android:layout_width="match_parent"
                android:layout_alignParentTop="true"
                android:layout_height="50dp"
                android:layout_marginTop="5pt"
                android:layout_marginLeft="10pt"
                android:layout_marginRight="10pt"
                android:elevation="4pt"
                android:background="@drawable/white_border" >

                <ImageView
                    android:id="@+id/pickupIV"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_marginRight="3pt"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="5pt"
                    android:src="@drawable/ic_search"
                    app:tint="@color/colorPrimaryDark"/>

                <AutoCompleteTextView
                    android:id="@+id/pickupATV"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_toRightOf="@+id/pickupIV"
                    android:layout_centerVertical="true"
                    android:textSize="15sp"
                    android:textColor="@color/colorBlack"
                    android:background="@null"
                    android:hint="Search location"
                    android:singleLine="true"
                    android:imeOptions="actionSearch"/>

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/dropoffRL"
                android:layout_marginTop="5pt"
                android:layout_below="@id/pickupRL"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10pt"
                android:layout_marginRight="10pt"
                android:elevation="4pt"
                android:background="@drawable/white_border" >

                <ImageView
                    android:id="@+id/dropoffIV"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_marginRight="3pt"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="5pt"
                    android:src="@drawable/ic_search"
                    app:tint="@color/colorPrimaryDark"/>

                <AutoCompleteTextView
                    android:id="@+id/dropoffATV"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_toRightOf="@+id/dropoffIV"
                    android:layout_centerVertical="true"
                    android:textSize="15sp"
                    android:textColor="@color/colorBlack"
                    android:background="@null"
                    android:hint="Search location"
                    android:singleLine="true"
                    android:imeOptions="actionSearch"/>

            </RelativeLayout>

            <Button
                android:id="@+id/btnconfirm"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="30dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:padding="20dp"
                android:text="Comfirm" />

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/currentLocationFAB"
                android:backgroundTint="@color/colorWhite"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@id/btnconfirm"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="5pt"
                android:layout_marginRight="10pt"
                android:elevation="4pt"
                app:fabSize="mini"
                app:borderWidth="0dp"
                app:elevation="4pt"
                app:backgroundTint="@color/colorWhite"
                android:src="@drawable/ic_current_location"
                android:tint="@color/colorPrimaryDark"/>

        </RelativeLayout>
PlaceAutocompleteAdapter.java

public class DashboardActivity extends AppCompatActivity implements OnMapReadyCallback, View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {

    private Activity activity;
    private GoogleMap mMap;
    private static final String Tag = "MAP_ACTIVITY";
    private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
    private static final String COURSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
    private static final float DEFAULT_ZOOM = 15f;
    private static final LatLngBounds LAT_LNG_BOUNDS = new LatLngBounds(
            new LatLng(-40, -168), new LatLng(71, 136));

    private Boolean mLocationPermissionsGranted = false;
    private FusedLocationProviderClient mFusedLocationProviderClient;
    private final ThreadLocal<PlaceAutocompleteAdapter> mplaceAutoCompeleteAdapter = new ThreadLocal<>();

    private GoogleApiClient mGoogleApiClient;
    private PlaceInfo mPlace;

    private AutoCompleteTextView pickupATV, dropoffATV;
    private Button btnconfirm;
    private FloatingActionButton currentLocationFAB;
    private Toolbar toolbar;
    private MenuItem previousItem;
    private UtilityModel utilityModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);

        bindControls();
        bindListeners();
        getLocationPermission();
        setMap();
    }

    private void getLocationPermission() {
        String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION};

        if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
                FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
                    COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                mLocationPermissionsGranted = true;
                setMap();
            } else {
                ActivityCompat.requestPermissions(this,
                        permissions,
                        LOCATION_PERMISSION_REQUEST_CODE);
            }
        } else {
            ActivityCompat.requestPermissions(this,
                    permissions,
                    LOCATION_PERMISSION_REQUEST_CODE);
        }
    }

    private void bindControls() {
        activity = DashboardActivity.this;
        utilityModel = new UtilityModel(activity);
        toolbar = findViewById(R.id.toolbar);

        btnconfirm = findViewById(R.id.btnconfirm);
        pickupATV = findViewById(R.id.pickupATV);
        dropoffATV = findViewById(R.id.dropoffATV);
        currentLocationFAB = findViewById(R.id.currentLocationFAB);
    }


    private void bindListeners() {
        btnconfirm.setOnClickListener(this);

        mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(com.google.android.gms.location.places.Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();

        mplaceAutoCompeleteAdapter.set(new PlaceAutocompleteAdapter(activity, mGoogleApiClient, LAT_LNG_BOUNDS, null));
        pickupATV.setOnItemClickListener(mAutocompleteClickListener);
        pickupATV.setAdapter(mplaceAutoCompeleteAdapter); // This adapter is causing the trouble
        pickupATV.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH
                        || actionId == EditorInfo.IME_ACTION_DONE
                        || keyEvent.getAction() == KeyEvent.ACTION_DOWN
                        || keyEvent.getAction() == KeyEvent.KEYCODE_ENTER) {

                    //execute our method for searching
                    geoLocate(pickupATV);
                }

                return false;
            }
        });

        dropoffATV.setOnItemClickListener(mAutocompleteClickListener);
        mplaceAutoCompeleteAdapter.set(new PlaceAutocompleteAdapter(activity, mGoogleApiClient, LAT_LNG_BOUNDS, null));
        dropoffATV.setAdapter(mplaceAutoCompeleteAdapter); // This adapter is causing the trouble
        dropoffATV.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH
                        || actionId == EditorInfo.IME_ACTION_DONE
                        || keyEvent.getAction() == KeyEvent.ACTION_DOWN
                        || keyEvent.getAction() == KeyEvent.KEYCODE_ENTER) {

                    //execute our method for searching
                    geoLocate(dropoffATV);
                }

                return false;
            }
        });

        currentLocationFAB.setOnClickListener(this);
        utilityModel.hideSoftKeyboard();
    }

    private AdapterView.OnItemClickListener mAutocompleteClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            utilityModel.hideSoftKeyboard();

            final AutocompletePrediction item = mplaceAutoCompeleteAdapter.get().getItem(i);
            final String placeId = item.getPlaceId();

            PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
                    .getPlaceById(mGoogleApiClient, placeId);
            placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
        }
    };

    private ResultCallback<PlaceBuffer> mUpdatePlaceDetailsCallback = new ResultCallback<PlaceBuffer>() {
        @SuppressLint("RestrictedApi")
        @Override
        public void onResult(@NonNull PlaceBuffer places) {
            if(!places.getStatus().isSuccess()){
                Log.d(Tag, "onResult: Place query did not complete successfully: " + places.getStatus().toString());
                places.release();
                return;
            }
            final Place place = places.get(0);

            try{
                mPlace = new PlaceInfo();
                mPlace.setName(place.getName().toString());
                Log.d(Tag, "onResult: name: " + place.getName());
                mPlace.setAddress(place.getAddress().toString());
                Log.d(Tag, "onResult: address: " + place.getAddress());
                mPlace.setAttributions(place.getAttributions().toString());
//                Log.d(TAG, "onResult: attributions: " + place.getAttributions());
                mPlace.setId(place.getId());
                Log.d(Tag, "onResult: id:" + place.getId());
                mPlace.setLatlng(place.getLatLng());
                Log.d(Tag, "onResult: latlng: " + place.getLatLng());
                mPlace.setRating(place.getRating());
                Log.d(Tag, "onResult: rating: " + place.getRating());
                mPlace.setPhoneNumber(place.getPhoneNumber().toString());
                Log.d(Tag, "onResult: ic_phone number: " + place.getPhoneNumber());
                mPlace.setWebsiteUri(place.getWebsiteUri());
                Log.d(Tag, "onResult: website uri: " + place.getWebsiteUri());
                Log.d(Tag, "onResult: place: " + mPlace.toString());
            }catch (NullPointerException e){
                Log.e(Tag, "onResult: NullPointerException: " + e.getMessage() );
            }
            setMarkerAndMoveCamera(new LatLng(place.getViewport().getCenter().latitude,
                    place.getViewport().getCenter().longitude), mPlace);
            currentLocationFAB.setVisibility(View.VISIBLE);

            places.release();
        }
    };

    private void geoLocate(AutoCompleteTextView view) {
        String searchString = view.getText().toString().trim();

        Geocoder geocoder = new Geocoder(activity);
        List<Address> list = new ArrayList<>();
        try {
            list = geocoder.getFromLocationName(searchString, 1);
        } catch (IOException e) {
            Log.e(Tag, "geoLocate: IOException: " + e.getMessage());
        }

        if (list.size() > 0) {
            Address address = list.get(0);

            setMarkerAndMoveCamera(new LatLng(address.getLatitude(), address.getLongitude()), null);
        }
    }

    private void setMap() {
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        if (mLocationPermissionsGranted) {
            getCurrentLocation();
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            mMap.setMyLocationEnabled(true);
            mMap.getUiSettings().setMyLocationButtonEnabled(false);

            mMap.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
                @SuppressLint("RestrictedApi")
                @Override
                public void onCameraMove() {
                    currentLocationFAB.setVisibility(View.VISIBLE);
                }
            });

            mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
                @Override
                public void onMarkerDragStart(Marker marker) {

                }

                @Override
                public void onMarkerDrag(Marker marker) {

                }

                @SuppressLint("RestrictedApi")
                @Override
                public void onMarkerDragEnd(Marker marker) {
                    setMarkerAndMoveCamera(marker.getPosition(), null);
                    currentLocationFAB.setVisibility(View.VISIBLE);
                }
            });

            mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
                @SuppressLint("RestrictedApi")
                @Override
                public void onMapClick(LatLng latLng) {
                    setMarkerAndMoveCamera(latLng, null);
                    currentLocationFAB.setVisibility(View.VISIBLE);
                }
            });
        }
    }

    private void getCurrentLocation() {
        mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
        try {
            if (mLocationPermissionsGranted) {
                final Task location = mFusedLocationProviderClient.getLastLocation();
                location.addOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(@NonNull Task task) {
                        if (task.isSuccessful()) {
                            Log.d(Tag, "onComplete: found location!");
                            Location currentLocation = (Location) task.getResult();
                            setMarkerAndMoveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),null);
                        } else {
                            Log.d(Tag, "onFailed: current location is null");
                            Toast.makeText(activity, "unable to get current location", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        } catch (SecurityException e) {
            Log.e(Tag, "getCurrentLocation: SecurityException: " + e.getMessage());
        }
    }

    private void setMarkerAndMoveCamera(LatLng latLng, PlaceInfo placeInfo){
        mMap.clear();
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, DEFAULT_ZOOM));
    }


    @SuppressLint("RestrictedApi")
    @Override
    public void onClick(View v) {
        if (v == btnconfirm) {
//            LatLng currentMarkerLocation = mMap.getCameraPosition().target;
        }  else if (v == currentLocationFAB) {
            currentLocationFAB.setVisibility(View.INVISIBLE);
            getCurrentLocation();
        }
    }

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

    }
}
public class PlaceInfo {
    private String name;
    private String address;
    private String phoneNumber;
    private String id;
    private Uri websiteUri;
    private LatLng latlng;
    private float rating;
    private String attributions;

    public PlaceInfo(String name, String address, String phoneNumber, String id, Uri websiteUri,
                     LatLng latlng, float rating, String attributions) {
        this.name = name;
        this.address = address;
        this.phoneNumber = phoneNumber;
        this.id = id;
        this.websiteUri = websiteUri;
        this.latlng = latlng;
        this.rating = rating;
        this.attributions = attributions;
}

    public PlaceInfo() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Uri getWebsiteUri() {
        return websiteUri;
    }

    public void setWebsiteUri(Uri websiteUri) {
        this.websiteUri = websiteUri;
    }

    public LatLng getLatlng() {
        return latlng;
    }
    public void setLatlng(LatLng latlng) {
        this.latlng = latlng;
    }

    public float getRating() {
        return rating;
    }

    public void setRating(float rating) {
        this.rating = rating;
    }

    public String getAttributions() {
        return attributions;
    }

    public void setAttributions(String attributions) {
        this.attributions = attributions;
    }

    @Override
    public String toString() {
        return "PlaceInfo{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", phoneNumber='" + phoneNumber + '\'' +
                ", id='" + id + '\'' +
                ", websiteUri=" + websiteUri +
                ", latlng=" + latlng +
                ", rating=" + rating +
                ", attributions='" + attributions + '\'' +
                '}';
    }
}
public class PlaceAutocompleteAdapter
    extends ArrayAdapter<AutocompletePrediction> implements Filterable {

private static final String TAG = "PlaceAutocompleteAd";
private static final CharacterStyle STYLE_BOLD = new StyleSpan(Typeface.BOLD);
private ArrayList<AutocompletePrediction> mResultList;
private GoogleApiClient mGoogleApiClient;
private LatLngBounds mBounds;
private AutocompleteFilter mPlaceFilter;
public PlaceAutocompleteAdapter(Context context, GoogleApiClient googleApiClient,
                                LatLngBounds bounds, AutocompleteFilter filter) {
    super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1);
    mGoogleApiClient = googleApiClient;
    mBounds = bounds;
    mPlaceFilter = filter;
}

public void setBounds(LatLngBounds bounds) {
    mBounds = bounds;
}

@Override
public int getCount() {
    return mResultList.size();
}

@Override
public AutocompletePrediction getItem(int position) {
    return mResultList.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = super.getView(position, convertView, parent);

    AutocompletePrediction item = getItem(position);

    TextView textView1 = row.findViewById(android.R.id.text1);
    TextView textView2 = row.findViewById(android.R.id.text2);
    textView1.setText(item.getPrimaryText(STYLE_BOLD));
    textView2.setText(item.getSecondaryText(STYLE_BOLD));

    return row;
}

@Override
public Filter getFilter() {
    return new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();

            ArrayList<AutocompletePrediction> filterData = new ArrayList<>();

            if (constraint != null) {
                filterData = getAutocomplete(constraint);
            }

            results.values = filterData;
            if (filterData != null) {
                results.count = filterData.size();
            } else {
                results.count = 0;
            }

            return results;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {

            if (results != null && results.count > 0) {
                mResultList = (ArrayList<AutocompletePrediction>) results.values;
                notifyDataSetChanged();
            } else {
                notifyDataSetInvalidated();
            }
        }

        @Override
        public CharSequence convertResultToString(Object resultValue) {
            if (resultValue instanceof AutocompletePrediction) {
                return ((AutocompletePrediction) resultValue).getFullText(null);
            } else {
                return super.convertResultToString(resultValue);
            }
        }
    };
}

private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient.isConnected()) {
        Log.i(TAG, "Starting autocomplete query for: " + constraint);

        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);

        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);

        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");

        return DataBufferUtils.freezeAndClose(autocompletePredictions);
    }
    Log.e(TAG, "Google API client is not connected for autocomplete query.");
    return null;
}
公共类PlaceAutocompleteAdapter
扩展ArrayAdapter实现可筛选{
私有静态最终字符串TAG=“placeautocompleted”;
private static final CharacterStyle_BOLD=新样式span(Typeface.BOLD);
私有ArrayList mResultList;
私人GoogleapClient MGoogleapClient;
私人LatLngBounds mBounds;
专用自动完成过滤器;
public PlaceAutocompleteAdapter(上下文上下文、GoogleAppClient、GoogleAppClient、,
LatLngBounds边界,自动完成过滤器(过滤器){
super(context,android.R.layout.simple\u可扩展\u list\u item\u 2,android.R.id.text1);
mGoogleApiClient=googleApiClient;
mBounds=边界;
mPlaceFilter=过滤器;
}
公共无效收进边界(LatLngBounds边界){
mBounds=边界;
}
@凌驾
public int getCount(){
返回mResultList.size();
}
@凌驾
公共自动完成预测getItem(int位置){
返回mResultList.get(位置);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图行=super.getView(位置、转换视图、父级);
自动完成预测项=获取项(位置);
TextView textView1=row.findviewbyd(android.R.id.text1);
TextView textView2=row.findviewbyd(android.R.id.text2);
textView1.setText(item.getPrimaryText(STYLE_BOLD));
textView2.setText(item.getSecondaryText(样式为粗体));
返回行;
}
@凌驾
公共过滤器getFilter(){
返回新筛选器(){
@凌驾
受保护的筛选器结果性能筛选(CharSequence约束){
FilterResults results=新的FilterResults();
ArrayList filterData=新的ArrayList();
if(约束!=null){
filterData=getAutocomplete(约束);
}
results.values=过滤数据;
如果(filterData!=null){
results.count=filterData.size();
}否则{
结果:1.count=0;
}
返回结果;
}
@凌驾
受保护的void publishResults(CharSequence约束、FilterResults结果){
if(results!=null&&results.count>0){
mResultList=(ArrayList)results.values;
notifyDataSetChanged();
}否则{
notifyDataSetionValidated();
}
}
@凌驾
public CharSequence ConvertResultString(对象结果值){
if(自动完成预测的结果值实例){
返回((自动完成预测)结果值).getFullText(空);
}否则{
返回super.convertResultToString(resultValue);
}
}
};
}
私有ArrayList getAutocomplete(字符序列约束){
if(mgoogleapClient.isConnected()){
Log.i(标记“为“+约束”启动自动完成查询);
Pendingreult结果=
Places.GeoDataApi
.getAutocompletePredictions(mgoogleAppClient,constraint.toString(),
mBounds,mPlaceFilter);
AutocompletePredictionBuffer autocompletePredictions=结果
.等待(60,时间单位秒);
最终状态状态=自动完成预测。getStatus();
如果(!status.issucess()){
Toast.makeText(getContext(),“联系API时出错:”+status.toString(),
吐司。长度(短)。show();
Log.e(标记,“获取自动完成预测API调用时出错:”+status.toString());
autocompletePredictions.release();
返回null;
}
Log.i(标记“querycompleted.Received”+autocompletedpredictions.getCount()
+"预测";;
返回数据缓冲区。冻结并关闭(自动完成预测);
}
e(标记“GoogleAPI客户端未连接以进行自动完成查询”);
返回null;
}
}

我的错误位于
pickupATV.setAdapter
dropoffATV.setAdapter
上的
bindListener
方法中的
DashboardActivity.java

生成错误

任务:应用程序:CompiledBugJavaWithJavaC失败 /Users/muhammadyousuf/StudioProjects/homemoversfyp/app/src/main/java/com/example/daniyal/fyp_project/activities/DashboardActivity.java:162: 错误:无法删除类AutoCompleteTextView中的方法setAdapter 适用于给定类型; pickupATV.setAdapter(mplaceautompleteadapter);//此适配器导致了故障 ^必需:未找到:ThreadLocal原因:推断的类型不存在 符合上限 推断:ThreadLocal 上限:ListAdapter,可过滤,其中T是类型变量: T扩展ListAdapter,在方法setAdapter(T)中声明了Filterable /Users/muhammadyousuf/StudioProjects/homemoversfyp/app/src/main/java/com/example/daniyal/fyp_project/activities/DashboardActivity.java:181: 错误:无法删除类AutoCompleteTextView中的方法setAdapter 适用于给定类型; dropoffATV.setAdapter(mplaceautompleteadapter);//此适配器导致了故障 ^必需:未找到:ThreadLocal原因:推断的类型不存在 符合上限 推断:ThreadLocal 上限:ListAdapter,可过滤,其中T是类型变量: T扩展了ListAdapter,在方法setAdapter(T)中声明了Filterable注意:一些输入文件使用或重写了不推荐的 应用程序编程接口。注意:有关详细信息,请使用-Xlint:deprecation重新编译。注: /用户/穆罕默德
Places.initialize(getApplicationContext(), getResources().getString(R.string.google_maps_key));
PlacesClient placesClient = Places.createClient(activity);
pickupFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.pickupFragment);
pickupFragment.setCountry("PK");
pickupFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG));
pickupFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            Log.e(TAG, "Place: " + place.getName() + ", " + place.getId() + ", " + place.getLatLng());
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            Log.e(TAG, "An error occurred: " + status);
        }
    });
<fragment
 android:id="@+id/pickupFragment"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" />