DBHelper helper =
new
DBHelper(getApplicationContext(),
"movie.db"
,
null
,
1
);
SQLiteDatabase db = helper.getWritableDatabase();
helper.onCreate(db);
likelist = (ListView) findViewById(R.id.likeListView);
like =
new
ArrayList<>();
final
TextView userName = (TextView) findViewById(R.id.userName);
arrAdapter =
new
ArrayAdapter<String>(
this
, android.R.layout.simple_list_item_single_choice, like);
likelist.setAdapter(arrAdapter);
final
Cursor c = db.query(
"like"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
);
while
(c.moveToNext()) {
arrAdapter.add(c.getString(c.getColumnIndex(
"title"
)));
}
likelist.setOnItemClickListener(
new
AdapterView.OnItemClickListener() {
@Override
public
void
onItemClick(AdapterView<?> parent, View view,
int
position,
long
id) {
final
int
count;
final
int
[] checked =
new
int
[
1
];
count = arrAdapter.getCount();
new
AlertDialog.Builder(ProfileActivity.
this
)
.setTitle(
"취소"
).setMessage(
"삭제"
)
.setPositiveButton(
"삭제"
,
new
DialogInterface.OnClickListener() {
public
void
onClick(DialogInterface dialog,
int
whichButton) {
if
(count >
0
) {
checked[
0
] = likelist.getCheckedItemPosition();
if
(checked[
0
] > -
1
&& checked[
0
] < count) {
new
Thread(
new
Runnable() {
@Override
public
void
run() {
runOnUiThread(
new
Runnable() {
@Override
public
void
run() {
c.moveToPosition(checked[
0
]);
like.remove(c.getString(c.getColumnIndex(
"title"
)));
likelist.clearChoices();
arrAdapter.notifyDataSetChanged();
}
});
}
}).start();
}
}
}
})
.setNegativeButton(
"취소"
,
new
DialogInterface.OnClickListener() {
public
void
onClick(DialogInterface dialog,
int
whichButton) {
}
})
.show();
}
});