我对我的项目有recylerview,我用databasehelper存储我的recyclerview。我可以删除我的recyclerview项目,但我不能存储(保存)这个。如何删除ı储存在我的回收站。你能快点吗。我要删除ı储存在我的回收站。
主要活动
public class todolist extends AppCompatActivity implements BottomSheetDialogx.BottomSheetListener {
Button backhome,listeo;
private long backPressedTime;
RecyclerView recyclerView;
List<String> Lists = new ArrayList<>();
CustomAdapter adapter;
DatabaseHelper3 myDBxx;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todolist);
myDBxx = new DatabaseHelper3(this);
Cursor dataxx = myDBxx.getListContents();
if(dataxx.getCount() == 0){
Toast.makeText(this, "Liste Oluşturun!", Toast.LENGTH_LONG).show();
}else{
while(dataxx.moveToNext()){
Lists.add(dataxx.getString(1));
}
}
recyclerView=findViewById(R.id.recyclerviewx);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
adapter=new CustomAdapter(Lists);
recyclerView.setAdapter(adapter);
listeo=findViewById(R.id.listeolustur);
listeo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog();
bottomSheetDialog.show(getSupportFragmentManager(), "BottomSheet");
}
});
backhome = findViewById(R.id.backhome);
backhome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(todolist.this, pomodoroscreen.class);
startActivity(i);
overridePendingTransition(0,0);
}
});
ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.LEFT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
int positionx = viewHolder.getAdapterPosition();
Lists.remove(positionx);
adapter.notifyItemRemoved(positionx);
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
}
@Override
public void onButtonClick(String text) {
Lists.add(text);
adapter.notifyItemInserted(Lists.size());
AddDatax(text);
}
public void AddDatax(String newEntry) {
boolean insertDatax = myDBxx.addDataxx(newEntry);
}
}
数据库助手.java
public class DatabaseHelper3 extends SQLiteOpenHelper {
public static final String DATABASE_NAME3 = "mylistxx.db";
public static final String TABLE_NAME3 = "mylist_dataxx";
public static final String COL13 = "IDxx";
public static final String COL23 = "ITEM1xx";
public DatabaseHelper3(Context context) {
super(context, DATABASE_NAME3, null, 1);
}
@Override
public void onCreate(SQLiteDatabase dbx) {
String createTable = "CREATE TABLE " + TABLE_NAME3 + " (IDxx INTEGER PRIMARY KEY AUTOINCREMENT, " +
" ITEM1xx TEXT)";
dbx.execSQL(createTable);
}
@Override
public void onUpgrade(SQLiteDatabase dbxx, int oldVersion, int newVersion) {
dbxx.execSQL("DROP IF TABLE EXISTS " + TABLE_NAME3);
onCreate(dbxx);
}
public boolean addDataxx(String textt) {
SQLiteDatabase dbxx = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL23, textt);
long result = dbxx.insert(TABLE_NAME3, null, contentValues);
if (result == -1) {
return false;
} else {
return true;
}
}
public Cursor getListContents(){
SQLiteDatabase dbxx = this.getWritableDatabase();
Cursor dataxx = dbxx.rawQuery("SELECT * FROM " + TABLE_NAME3, null);
return dataxx;
}
}
暂无答案!
目前还没有任何答案,快来回答吧!