私のデータベースにはいくつかの値があり、私のカスタムListViewの値にカスタムCursor Adapterを設定しています。人がlistViewをクリックすると新しいアクティビティが開き、その値またはビューの削除ボタンが消え、リストを更新する必要があります。リストビューからビュー/値を削除する
私はSOの多くの回答を参考にしましたが、データベースから値を取り除くことを提案しました(これは私が望むものではありません)。また、ArrayListを使用してカスタムアレイアダプタで使用するように勧めました。カーソルアダプターを使用しています。
私の全質問は、値を削除するか、リストビューからビューを削除することですか?
ListView項目のonClickリスナーは
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Constants.ROW_NUMBER=position;
TextView getRecordID = (TextView) view.findViewById(R.id.recordID);
Constants.ROW_NUMBER = Integer.parseInt(getRecordID.getText().toString());
Intent editIntent = new Intent(this,NoteDisplay.class);
editIntent.putExtra(Constants.ROW_NAME,Constants.ROW_NUMBER);
startActivity(editIntent);
}
これは新しい活動であるとレコードが削除済みとしてマークされますが、データベースから削除されませんメニューボタンの押しに新しいアクティビティを開きます。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case R.id.deletebutton:
DataBaseHelper deletedb = new DataBaseHelper(this);
int deletedata = deletedb.deleteAction(position,System.currentTimeMillis());
Intent dintent = new Intent(this,MainActivity.class);
dintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(dintent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
これは、私は、この時点でビューまたは値を削除するかどうか混乱しています、
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(R.layout.customlistview, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
//int getDeleteFlag is initialized above
getDeleteFlag = cursor.getInt(cursor.getColumnIndex(DELETE_FLAG));
if(getDeleteFlag==0)
{
ll = (LinearLayout)view.findViewById(R.id.listViewLayout);
setListViewHeight(ll,context);
if (cursor != null) {
getText = cursor.getString(cursor.getColumnIndex(NOTE_TITLE));
existsRecordID = cursor.getString(cursor.getColumnIndex(RECORD_ID));
datevalue = cursor.getLong(cursor.getColumnIndex(RECORD_DATE));
}
Date newdate = new Date(datevalue);
tv = (TextView) view.findViewById(R.id.content);
recordID = (TextView) view.findViewById(R.id.recordID);
dateET = (TextView) view.findViewById(R.id.date);
tv.setText(getText.trim());
recordID.setText(existsRecordID);
dateET.setText(dateFormatter.format(newdate));
}else{
Toast.makeText(context, "FALSE VALUE", Toast.LENGTH_SHORT).show();
}
}
私のカスタムカーソルアダプタクラスです。
1 =>削除済み 0 =>削除されていないDBに「deleteflag」という名前の行があります。
したがって、1の値だけが削除済みとしてマークされます。
EDIT 1:
私bindView()
方法で上記のコードは、あなたが0と1の値をデータベースにそのdeleteFlag値を格納する必要が
リストビューから削除すると、その時点で削除されますが、データベースからは削除されません。データベースから削除されていないため、そのページ(削除済みビュー)を再び見ることができます。 – Piyush
@Piyushどうすれば 'if(deleteflag == 0)'をチェックすれば、それ以外は表示されないのですか?はいの場合、これはどのように行うことができますか? –
そのフラグをデータベースに保存することができます – Piyush