找不到适用于ArrayAdapter的合适的构造函数

找不到适用于ArrayAdapter的合适的构造函数

问题描述:

我遇到以下错误:

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);

我还尝试用thisgetApplicationContext()context替换ArrayAdapter的第一个参数.不幸的是,它没有用.我真的不知道我在做什么错.

I have also tried to replace the first parameter of ArrayAdapter with this, getApplicationContext() or context. Unfortunately it didn't worked. I have really no idea what I'm doing wrong.

如果想查看以下代码,请在下面查看我的代码:

Here below you can see my code if you want to see it:

AllStores.java:

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();
        }
    }
}

ArrayAdapter<String>构造函数不接受ListViewResponse<List<Store>>,并且在您的代码中将它们都添加了

The ArrayAdapter<String> constructor doesn't accept ListView nor Response<List<Store>> and in your code you added them both

ArrayAdapter<String> stringArrayAdapter=new ArrayAdapter<String> AllStores.this, lv, subprises);

,但应使用Contextlayout resource idList<String>String[].一个简单的适配器就是

but it should take the Context, layout resource id and the List<String> or String[]. A simple adapter would be

ArrayAdapter<String> adapter = new ArrayAdapter<>(AllStores.this, android.R.layout.simple_list_item_1, your_string_array_or_list);

然后将适配器设置为ListView

lv.setAdapter(adatper);

如果要使用更复杂的适配器,则应创建一个自定义的ArrayAdapter.查看此链接
http://www.ezzylearning.com/tutorial/customizing -android-listview-items-with-custom-arrayadapter

If you want more complex adapter, you should create a custom ArrayAdapter. Check out this link
http://www.ezzylearning.com/tutorial/customizing-android-listview-items-with-custom-arrayadapter