我正在制作包含书签的webview应用程序,我使用Cursor和SQLite 数据库成功将项目添加到listView中,但我的问题是我无法获取项目的位置并删除它我尝试以自己的方式执行此操作,但我得到的是我已经删除了列表视图的所有内容。这是我的MainActivity,我制作了一个longClickItemListener来删除长按时的列表视图项目,这是我的BookmarkDatabase
主要活动
final Dialog bookmarksScreen = new Dialog(this);
bookmarksScreen.requestWindowFeature(Window.FEATURE_NO_TITLE);
bookmarksScreen.setContentView(R.layout.activity_bookmark);
bookmarksScreen.setCancelable(true);
final ListView listView = bookmarksScreen.findViewById(R.id.bookmark_list);
ImageView bookmarkBack = bookmarksScreen.findViewById(R.id.close_bookmarks);
ImageView bookmarkDelete = bookmarksScreen.findViewById(R.id.delete_table);
// populate an ArrayList<String> from the database and then view it
final ArrayList<String> theList = new ArrayList<>();
Cursor data = bookmarkDB.getListContents();
// check if there is no data on database
if(data.getCount() == 0){
Log.d("Database Bookmark", "There is no items on item list");
} else {
while(data.moveToNext()) {
// add data into table "COL1" and "COL2"
theList.add(data.getString(1));
ListAdapter listAdapter = new ArrayAdapter<>(this, R.layout.activity_listitem, theList);
listView.setAdapter(listAdapter);
}
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
webView.loadUrl(item);
bookmarksScreen.dismiss();
}
});
ITMISS
相关分类