}
---------------------------------------------------------------------------------------------------------
public class LvAdapter extends BaseAdapter {
private List
private Context mContext;
public LvAdapter(List
mBeans = beans;
mContext = context;
}
public void notifyData(List
mBeans = beans;
notifyDataSetChanged();
}
@Override
public int getCount() {
return mBeans.size();
}
@Override
public Object getItem(int i) {
return mBeans.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder vh;
if (view == null) {
vh = new ViewHolder();
view = LayoutInflater.from(mContext).inflate(R.layout.lv_item, viewGroup, false);
vh.img = view.findViewById(R.id.item_img);
vh.tv = view.findViewById(R.id.item_tv);
view.setTag(vh);
} else {
vh = (ViewHolder) view.getTag();
}
Glide.with(mContext).load(mBeans.get(i).getImage()).into(vh.img);
vh.tv.setText(mBeans.get(i).getTitle());
return view;
}
static class ViewHolder {
ImageView img;
TextView tv;
}
}
-----------------------------------------------------------------------------------------
@Entity
public class DaoBean {
private String img;
private String title;
@Generated(hash = 1826550138)
public DaoBean(String img, String title) {
this.img = img;
this.title = title;
}
@Generated(hash = 405743142)
public DaoBean() {
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
----------------------------------------------------------------------------------
public class MyContentProvider extends ContentProvider {
String path = "content://com.bwie.weekexam03_demo/film";
SQLiteDatabase mDb;
@Override
public boolean onCreate() {
MySQLiteOpenHelper helper = new MySQLiteOpenHelper(getContext());
mDb = helper.getWritableDatabase();
return false;
}
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) {
Cursor cursor = mDb.query("film", strings, s, strings1, null, null, s1);
return cursor;
}
@Nullable
@Override
public String getType(@NonNull Uri uri) {
return null;
}
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
long insert = mDb.insert("film", null, contentValues);
Uri uri1 = ContentUris.withAppendedId(Uri.parse(path), insert);
return uri1;
}
@Override
public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
return 0;
}
@Override
public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) {
return 0;
}
}
---------------------------------------------------------------------------------------
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
public static final String DB_NAME = "film.db";
public static final int DB_VERSION = 1;
public MySQLiteOpenHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("create table film(_id integer primary key autoincrement," +
"img text," +
"title text)");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
----------------------------------------------------------------------------------------------
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:name=".MyContentProvider"
android:exported="true"
android:enabled="true"/>
-------------------------------------------------------------------------
resolver*******
public class MainActivity extends AppCompatActivity {
private ContentResolver mResolver;
private String path = "content://com.bwie.weekexam03_demo/film";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mResolver = getContentResolver();
// 添加数据
ContentValues values = new ContentValues();
values.put("key", "value");
values.put("key", "value");
values.put("key", "value");
mResolver.insert(Uri.parse(path),values);
// 查询数据
Cursor cursor = mResolver.query(Uri.parse(path),
null, null, null, null);
while (cursor.moveToNext()) {
cursor.getColumnIndex("name");
}
}
}