我成功地想出了如何将我的肥皂对象留在记忆中。现在我试图将我已经返回到ListView中的内容。
我的自定义类看起来像这样
public class JudgmentInformationClass {
public static class PipelineGridViewClass {
private String CaseId;
private double Amount;
private String CaseDescription;
private Date JudgmentDate;
}
}
这正是我正在寻找10行此信息的内容。
现在我想将它发送到一个基本的列表视图。
我有一个自定义列表工作,但我无法弄清楚如何制作我的自定义arraylist。我收到以下错误。
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);
}
});
}
答案 0 :(得分:1)
您不能以这种方式使用ArrayAdapter。
由于您声明ArrayAdapter<String> arrayAdapter
,因此无法使用带
ArrayAdapter(MainActivity,int,ArrayList<PipelineGridViewClass>)
这是你问题的原因:
错误:(103,53)错误:找不到适合ArrayAdapter的构造函数(MainActivity,int,ArrayList) 构造函数ArrayAdapter.ArrayAdapter(Context,int,int,List)不适用
你可以像这样使用somenthing:
ArrayAdapter<PipelineGridViewClass> arrayAdapter = new ArrayAdapter<PipelineGridViewClass>(
MainActivity.this,
android.R.layout.simple_list_item_1,
pipelineview);
注意doc:
但是引用了TextView,它将填充数组中每个对象的toString()。您可以添加自定义对象的列表或数组。覆盖对象的toString()方法,以确定将为列表中的项显示哪些文本。
这意味着您必须覆盖toString()
类的PipelineGridViewClass
。