package cn.itcast.notepad;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import java.util.List;
import cn.itcast.notepad.adapter.NotepadAdapter;
import cn.itcast.notepad.bean.NotepadBean;
import cn.itcast.notepad.database.SQLiteHelper;
public class NotepadActivity extends Activity {
ListView listView;
List<NotepadBean> list;
SQLiteHelper mSQLiteHelper;
NotepadAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notepad);
//用于显示便签的列表
listView = (ListView) findViewById(R.id.listview);
ImageView add = (ImageView) findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(NotepadActivity.this,
RecordActivity.class);
startActivityForResult(intent, 1);
}
});
initData();
}
protected void initData() {
mSQLiteHelper= new SQLiteHelper(this); //创建数据库
showQueryData();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
NotepadBean notepadBean = list.get(position);
Intent intent = new Intent(NotepadActivity.this, RecordActivity.class);
intent.putExtra("id", notepadBean.getId());
intent.putExtra("time", notepadBean.getNotepadTime()); //记录的时间
intent.putExtra("content", notepadBean.getNotepadContent()); //记录的内容
NotepadActivity.this.startActivityForResult(intent, 1);
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int
position, long id) {
AlertDialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder( NotepadActivity.this)
.setMessage("是否删除此事件?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
NotepadBean notepadBean = list.get(position);
if(mSQLiteHelper.deleteData(notepadBean.getId())){
list.remove(position);
adapter.notifyDataSetChanged();
Toast.makeText(NotepadActivity.this,"删除成功",
Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog = builder.create();
dialog.show();
return true;
}
});
}
private void showQueryData(){
if (list!=null){
list.clear();
}
//从数据库中查询数据(保存的标签)
list = mSQLiteHelper.query();
adapter = new NotepadAdapter(this, list);
listView.setAdapter(adapter);
}
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==1&&resultCode==2){
showQueryData();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
记事本的重要代码main.zip (31个子文件)
记事本的重要代码main
java
cn
itcast
notepad
adapter
NotepadAdapter.java 2KB
RecordActivity.java 4KB
utils
DBUtils.java 822B
database
SQLiteHelper.java 4KB
NotepadActivity.java 4KB
bean
NotepadBean.java 732B
res
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 6KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 3KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 276B
ic_launcher_round.xml 276B
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 9KB
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 4KB
values
colors.xml 214B
strings.xml 73B
styles.xml 394B
layout
notepad_item_layout.xml 875B
activity_notepad.xml 1KB
activity_record.xml 3KB
drawable
ic_launcher_background.xml 6KB
drawable-hdpi
save_note.png 5KB
add.png 5KB
back.png 3KB
delete.png 5KB
AndroidManifest.xml 815B
共 31 条
- 1
资源评论
Slowfish172
- 粉丝: 91
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功