繁体   English   中英

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

[英]no suitable constructor found for 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);

我也曾尝试更换的第一个参数ArrayAdapterthisgetApplicationContext()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();
        }
    }
}

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM