【发布时间】:2015-12-20 07:32:35
【问题描述】:
我收到以下错误:
Error:(34, 53) error: no suitable constructor found for ArrayAdapter(AllStores,ListView,Response<List<Store>>)
constructor ArrayAdapter.ArrayAdapter(Context,int,int,List<String>) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,List<String>) is not applicable
(actual argument ListView cannot be converted to int by method invocation conversion)
constructor ArrayAdapter.ArrayAdapter(Context,int,int,String[]) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,String[]) is not applicable
(actual argument ListView cannot be converted to int by method invocation conversion)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
(actual argument ListView cannot be converted to int by method invocation conversion)
constructor ArrayAdapter.ArrayAdapter(Context,int) is not applicable
(actual and formal argument lists differ in length)
这是我尝试过的:
ArrayAdapter<String> stringArrayAdapter=new ArrayAdapter<String>(
AllStores.this,
lv,
subprises);
我也尝试将ArrayAdapter的第一个参数替换为this、getApplicationContext()或context。不幸的是,它没有奏效。我真的不知道我做错了什么。
如果你想看的话,你可以在下面看到我的代码:
AllStores.java:
public class AllStores extends Activity {
private ListView lv;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_stores);
lv = (ListView) findViewById(R.id.store_list);
Response<List<Store>> subprises;
try {
subprises = new StoreService().getSubprises();
Iterator it = subprises.body().iterator();
ArrayAdapter<String> stringArrayAdapter=new ArrayAdapter<String>(
AllStores.this,
lv,
subprises);
} catch (IOException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
-
您正试图在
ArrayList的String中传递Object的Response<List<Store>>...您必须创建自己的扩展ArrayAdapter的适配器类,然后使它像这样。默认构造函数需要Context、layoutId、StringArray... -
可以看到自定义适配器的实现here
标签: java android android-arrayadapter