我在我的项目中使用了一个外部SQlite数据库,并在一个带有简单适配器的Listview中使用了它,实际上它可以正常工作,但是我想使用glide库在Listview中显示图像。我将图像url存储在数据库中,但我不知道如何将其传递给滑行,这可能与否? 预先感谢。
public class DatabaseHandler extends SQLiteOpenHelper {
private Context main_context;
private static String DB_PATH;
private static String DB_NAME = "ebook_db.db";
private static int DB_VERSION = 1;
private static String DB_TBL_BOOKS = "books";
private static String DB_TBL_SETTINGS = "settings";
private SQLiteDatabase db;
public DatabaseHandler(Context con) {
super(con, DB_NAME, null, DB_VERSION);
main_context = con;
DB_PATH = con.getCacheDir().getPath() + "/" + DB_NAME;
}
@Override
public void onCreate(SQLiteDatabase db) {
/* do nothing */
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
/* do nothing */
}
private boolean dbExists() {
File f = new File(DB_PATH);
if (f.exists())
return true;
else
return false;
}
private boolean copyDB() {
try {
FileOutputStream out = new FileOutputStream(DB_PATH);
InputStream in = main_context.getAssets().open(DB_NAME);
byte[] buffer = new byte[1024];
int ch;
while ((ch = in.read(buffer)) > 0) {
out.write(buffer, 0, ch);
}
out.flush();
out.close();
in.close();
return true;
} catch (Exception e) {
/* do nothing */
return false;
}
}
public void open() {
if (dbExists()) {
try {
File temp = new File(DB_PATH);
db = SQLiteDatabase.openDatabase(
temp.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE
);
} catch (Exception e) {
/* do nothing */
}
} else {
if (copyDB())
open();
}
}
@Override
public synchronized void close() {
db.close();
}
public List<HashMap<String,Object>> getTableOfContent(String id) {
Cursor result = db.rawQuery("SELECT * FROM " + DB_TBL_BOOKS + " WHERE author = '" + id + "'", null);
List<HashMap<String, Object>> all_data = new ArrayList<>();
while (result.moveToNext()) {
HashMap<String,Object> temp = new HashMap<>();
temp.put("id", result.getString(0));
temp.put("title", result.getString(1));
temp.put("author", result.getString(3));
temp.put("image", result.getString(8));
if (result.getString(9).equals("1")) {
temp.put("fav_flag", R.drawable.is_favorite);
} else {
temp.put("fav_flag", R.drawable.not_favorite);
}
if (result.getString(10).equals("1")) {
temp.put("see_flag", R.drawable.see);
} else {
temp.put("see_flag", R.drawable.not_see);
}
all_data.add(temp);
}
return all_data;
}
tblOfContent.java
public class tblOfContent extends AppCompatActivity {
private ListView contentListView;
private List<HashMap<String, Object>> books_list;
private DatabaseHandler db;
public String my_key_number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tbl_of_content);
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Bundle extras = getIntent().getExtras();
if (extras != null) {
my_key_number = extras.getString("number_of_keys");
Toast.makeText(this, my_key_number, Toast.LENGTH_LONG).show();
}
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
//actionBar.setTitle(R.string.doctors_title);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
contentListView = findViewById(R.id.tblOfContentListView);
db = new DatabaseHandler(getBaseContext());
db.open();
books_list = db.getTableOfContent(my_key_number);
String[] from = {"title", "image", "fav_flag", "see_flag"};
int[] to = {R.id.txtTitle, R.id.url, R.id.setFav, R.id.setSee};
SimpleAdapter adb = new SimpleAdapter(
getBaseContext(), books_list, R.layout.foods_row_item, from, to
);
contentListView.setAdapter(adb);
db.close();
contentListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(getBaseContext(), book_content.class);
String my_id = books_list.get(position).get("id").toString();
i.putExtra("id", my_id);
startActivity(i);
}
}
);
}
}
答案 0 :(得分:0)
尝试一下:
ERROR in src/assets/charting_library/charting_library.min.d.ts(1,23): error TS2688: Cannot find type definition file for 'jquery'.
src/assets/charting_library/charting_library.min.d.ts(121,14): error TS2304: Cannot find name 'JQuery'.
src/assets/charting_library/charting_library.min.d.ts(124,93): error TS2304: Cannot find name 'JQuery'.
src/assets/charting_library/charting_library.min.d.ts(259,40): error TS2304: Cannot find name 'JQueryEventObject'.
src/assets/charting_library/charting_library.min.d.ts(1205,47): error TS2304: Cannot find name 'JQuery'.
src/assets/datafeeds/udf/src/udf-compatible-datafeed-base.ts(243,74): error TS2339: Property 'errmsg' does not exist on type 'UdfErrorResponse | UdfSearchSymbolsResponse'.
Property 'errmsg' does not exist on type 'UdfSearchSymbolsResponse'.
src/assets/datafeeds/udf/src/udf-compatible-datafeed-base.ts(248,15): error TS2345: Argument of type 'UdfErrorResponse | UdfSearchSymbolsResponse' is not assignable to parameter of type 'SearchSymbolResultItem[]'.
Type 'UdfErrorResponse' is not assignable to type 'SearchSymbolResultItem[]'.
Property 'includes' is missing in type 'UdfErrorResponse'.
src/assets/datafeeds/udf/src/udf-compatible-datafeed-base.ts(284,21): error TS2345: Argument of type 'UdfErrorResponse | ResolveSymbolResponse' is not assignable to parameter of type 'LibrarySymbolInfo'.
Type 'UdfErrorResponse' is not assignable to type 'LibrarySymbolInfo'.
Property 'name' is missing in type 'UdfErrorResponse'.
希望有帮助!