无法解析构造函数'ArrayAdapter(com.alburraq.mapschoolbus.activities.AddChildActivity,int,void)'
我想在autoCompletetextview中显示arraylist
for (int i = 0; i < Constants.followArrayList.size(); i++) {
loadVehicles(Constants.followArrayList.get(i).getOwnerID());
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, loadVehicles(Constants.followArrayList.get(i).getOwnerID()) );
mAutocompleteTextViewBus.setThreshold(1); //will start working from first character
mAutocompleteTextViewBus.setAdapter(adapter);
}
private void loadVehicles(final String ownerID) {
FirebaseDatabase.getInstance().getReference("vehicles").orderByChild("ownerId").equalTo(ownerID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Vehicle vehicle = new Vehicle();
vehicle.setId("" + postSnapshot.getKey());
vehicle.setDriverName("" + postSnapshot.child("driverName").getValue());
vehicle.setDriverPhone("" + postSnapshot.child("driverPhone").getValue());
vehicle.setDriverPin("" + postSnapshot.child("driverPin").getValue());
vehicle.setImage("" + postSnapshot.child("image").getValue());
vehicle.setIsActive(Integer.parseInt("" + postSnapshot.child("isActive").getValue()));
vehicle.setLatitude("" + postSnapshot.child("latitude").getValue());
vehicle.setLongitude("" + postSnapshot.child("longitude").getValue());
vehicle.setNumber("" + postSnapshot.child("number").getValue());
vehicle.setOwnerId("" + postSnapshot.child("ownerId").getValue());
// if (vehicle.getIsActive() == 1) {
vehicles.add(vehicle);
//}
}
Constants.dismissSpinner();
}
@Override
public void onCancelled(DatabaseError error) {
Constants.dismissSpinner();
loadVehicles(ownerID);
}
});
Constants.dismissSpinner();
}
无法解析构造函数 'ArrayAdapter(com.alburraq.mapschoolbus.activities.AddChildActivity, int,void)'
答案 0 :(得分:0)
在ArrayAdapter
中的constructor ArrayAdapter(context, int, void)
不存在。
您正在使用:
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, loadVehicles(Constants.followArrayList.get(i).getOwnerID()) );
和loadVehicles(final String ownerID)
返回void
。
使用以下构造函数之一:
ArrayAdapter(Context context, int resource)
ArrayAdapter(Context context, int resource, int textViewResourceId)
ArrayAdapter(Context context, int resource, T[] objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int resource, List<T> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)
答案 1 :(得分:0)
您的问题所在:
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, loadVehicles(Constants.followArrayList.get(i).getOwnerID()) );
ArrayAdapter
仅有的通用构造函数是(from the docs):
ArrayAdapter(Context context,int resource)构造函数
ArrayAdapter(上下文上下文,int资源,int textViewResourceId) 构造函数
ArrayAdapter(上下文上下文,int资源,T []对象)构造函数。
ArrayAdapter(上下文上下文,int资源,int textViewResourceId, T []对象)的构造函数。
ArrayAdapter(上下文上下文,int资源,List对象) 构造函数
ArrayAdapter(上下文上下文,int资源,int textViewResourceId, 列出对象)构造函数
如果要通过loadVehicles
方法传递响应,则需要返回一个值。当前您拥有:private **void** loadVehicles(final String ownerID)
。