5-4作业运行报错
先做的显示部分,报错信息和代码如下:
public class DBAdapter extends CursorTreeAdapter { Context mContext; public DBAdapter(Cursor groupCursor, Context context) { super(groupCursor, context); mContext = context; } @Override protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) { TextView groupView = new TextView(context); return groupView; } @Override protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) { String type = cursor.getString(2); TextView groupView=(TextView) view; groupView.setText(type); } @Override protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) { TextView childView=new TextView(context); return childView; } @Override protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) { String name=cursor.getString(1); TextView childView=(TextView)view; childView.setText(name); childView.setPadding(30,0,0,0); } @Override protected Cursor getChildrenCursor(Cursor groupCursor) { return groupCursor; } } public class MainActivity extends AppCompatActivity { ContentResolver resolver; ExpandableListView foodList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Cursor dataCursor=getData(); foodList=findViewById(R.id.food_list); foodList.setAdapter(new DBAdapter(dataCursor,MainActivity.this)); } private Cursor getData() { resolver=getContentResolver(); Uri uri= Uri.parse("content://com.imooc.menuprovider"); Cursor c = resolver.query(uri,null,null,null,null); return c; } }
9
收起
正在回答 回答被采纳积分+1
Android从界面到数据存储2018版
- 参与学习 504 人
- 提交作业 1003 份
- 解答问题 1044 个
本专题是专为有Java语言基础想入坑Android开发的同学们准备的。从AndroidUI基础一直到网络,数据存储,一步到位入门Android开发。如果你会Java,那就不要犹豫了~ ~
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星