我已经成功地弄清楚了如何将我的肥皂对象存储在内存中。现在,我试图将返回的内容放入ListView。

我的自定义班级看起来像这样

public class JudgmentInformationClass {
    public static class PipelineGridViewClass {
        private String CaseId;
        private double Amount;
        private String CaseDescription;
        private Date JudgmentDate;
    }
}


这恰好返回我正在寻找此信息的10行。

现在,我想将其发送到基本列表视图。

我有一个自定义列表正在工作,但是我不知道如何制作自定义数组列表。我收到以下错误。

Error:(103, 53) error: no suitable constructor found for ArrayAdapter(MainActivity,int,ArrayList<PipelineGridViewClass>)
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 ArrayList<PipelineGridViewClass> cannot be converted to List<String> 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 ArrayList<PipelineGridViewClass> cannot be converted to String[] by method invocation conversion)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
(actual argument ArrayList<PipelineGridViewClass> 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)




 private void SetListView(Activity activity) {

    activity.runOnUiThread(new Runnable() {
        public void run() {
            ArrayList<JudgmentInformationClass.PipelineGridViewClass> pipelineview = JudgmentInformationClass.PipelineGridViewClass.PipelineGridView();
            //ArrayList<JudgmentInformationClass.PipelineGridView>
            lv = (ListView) findViewById(R.id.listview);
            /*List<String> your_array_list = new ArrayList<String>();
            your_array_list.add("foo");
            your_array_list.add("bar");*/
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                    MainActivity.this,
                    android.R.layout.simple_list_item_1,
                    pipelineview);

            lv.setAdapter(arrayAdapter);
        }
    });
}

最佳答案

您不能以这种方式使用ArrayAdapter。

由于您声明了ArrayAdapter<String> arrayAdapter,因此不能将构造函数与

ArrayAdapter(MainActivity,int,ArrayList<PipelineGridViewClass>)


这是您遇到问题的原因:


  错误:(103、53)错误:没有为ArrayAdapter(MainActivity,int,ArrayList)找到合适的构造函数
  构造函数ArrayAdapter.ArrayAdapter(Context,int,int,List)不适用


您可以使用类似这样的东西:

 ArrayAdapter<PipelineGridViewClass> arrayAdapter = new ArrayAdapter<PipelineGridViewClass>(
                    MainActivity.this,
                    android.R.layout.simple_list_item_1,
                    pipelineview);


注意doc


  但是,如果引用了TextView,它将使用数组中每个对象的toString()进行填充。您可以添加自定义对象的列表或数组。重写对象的toString()方法,以确定将为列表中的项目显示什么文本。


这意味着您必须重写toString()类的PipelineGridViewClass

关于android - 自定义类的ArrayList到ArrayAdapter的ListView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35395395/

10-12 02:32