private void flush() {
PrefVO.dataFlush();
noteVOList = access.findAllNote();
noteBaseAdapter = new NoteBaseAdapter(NotePadMainActivity.this, R.layout.item, noteVOList);
noteList.setAdapter(noteBaseAdapter);
noteNumText.setText(noteVOList.size() + “”);
}
private class OnItemSelectedListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
note = noteVOList.get(position);
Intent intent = new Intent();
intent.setClass(NotePadMainActivity.this, NotePadScanActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable(“note”, note);
intent.putExtra(“noteBundle”, bundle);
NotePadMainActivity.this.startActivity(intent);
}
}
private void showProgressDialog() {
pgDialog.setTitle(“loading…”);
pgDialog.setMessage(“少女祈祷中…”);
pgDialog.show();
new progressThread().start();
}
private Handler handler = new Handler(){
public void handleMessage(Message msg){
flush();
pgDialog.cancel();
}
};
private class progressThread extends Thread{
@Override
public void run() {
try{
Thread.sleep(1000);
handler.sendEmptyMessage(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
这里对列表日志设置了一个长按选项,长按后出现删除和短信发送的提示。
代码如下:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu,v,menuInfo);
menu.setHeaderIcon(R.drawable.shezhi);
menu.setHeaderTitle(“日志选项”);
menu.add(0,1,1,“删除”);
menu.add(0,2,2,“短信发送”);
}
public boolean onContextItemSelected(MenuItem item){
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
final NoteVO note = noteVOList.get(index);
switch (item.getItemId()){
case 1:{
AlertDialog.Builder builder = new AlertDialog.Builder(NotePadMainActivity.this);
builder.setTitle(“删除”);
builder.setIcon(R.drawable.shanchu);
builder.setMessage(“你确定要把日志删除吗?”);
builder.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DBAccess access = new DBAccess(NotePadMainActivity.this);
access.deleteNote(note);
dialog.dism