在Android开发中,你可以使用CursorAdapter或者ArrayAdapter来显示数据库中的数据。以下是一个使用CursorAdapter的例子: 首先,你需要创建一个CursorAdapter的子类,这个子类需要实现CursorAdapter的两个抽象方法:newView()和bindView()。 ```java public class MyCursorAdapter extends CursorAdapter { private LayoutInflater mInflater; public MyCursorAdapter(Context context, Cursor c, int flags) { super(context, c, flags); mInflater = LayoutInflater.from(context); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = mInflater.inflate(R.layout.list_item, parent, false); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { TextView textView = (TextView) view.findViewById(R.id.text); textView.setText(cursor.getString(cursor.getColumnIndex("column_name"))); } } ``` 然后,你需要在你的Activity中设置这个CursorAdapter: ```java public class MainActivity extends AppCompatActivity { private ListView listView; private MyCursorAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.listView); adapter = new MyCursorAdapter(this, mCursor, 0); listView.setAdapter(adapter); } } ``` 在这个例子中,你需要替换"column_name"为你的数据库中的列名,"list_item"为你的列表项的布局文件。 注意:在使用CursorAdapter时,你需要确保你的Cursor是打开的,并且在你的Activity的onDestroy()方法中关闭它。 [2023-11-07 22:40:14 | AI问答 | 347点数解答]