我想将新项目添加到列表视图的顶部
运行后,施力关闭
代码 :
final ArrayList<StructNote> notesPage = new ArrayList<StructNote>();
final ListView lstContent = (ListView) findViewById(R.id.lstContent);
adapter = new AdapterNote(notesPage);
View addNew = G.inflater.inflate(R.layout.addnew, null);
adapter.insert(addNew, 0);
lstContent.setAdapter(adapter);
adapter.notifyDataSetChanged();
错误日志:
04-01 15:39:02.163: E/AndroidRuntime(1908): java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to com.app.network.StructNote
04-01 15:39:02.163: E/AndroidRuntime(1908): at com.app.network.AdapterNote.getView(AdapterNote.java:612)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.makeAndAddView(ListView.java:1772)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.fillDown(ListView.java:672)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.fillFromTop(ListView.java:732)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.layoutChildren(ListView.java:1611)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.view.View.layout(View.java:11278)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.view.ViewGroup.layout(ViewGroup.java:4224)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
StructNote保存项目每个列表视图
结构说明:
public class StructNote {
public int id;
public String singer;
public String title;
}
AdapterNote设置为listview的listview的每个子级
适配器注:
public class AdapterNote extends ArrayAdapter<StructNote> {
public AdapterNote(ArrayList<StructNote> array) {
super(G.context, R.layout.post, array);
}
private static class ViewHolder {
...
}
试试这个:
final ArrayList<StructNote> notesPage = new ArrayList<StructNote>();
final ListView lstContent = (ListView) findViewById(R.id.lstContent);
adapter = new AdapterNote(notesPage);
LayoutInflater inflater = getLayoutInflater();
View addNew = inflater.inflate(R.layout.addnew, lstContent, false);
lstContent.addHeaderView(addNew, null, false);
lstContent.setAdapter(adapter);
adapter.notifyDataSetChanged();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句