package com.konlin.notebook;
import com.konlin.biz.BookBiz;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class Main extends Activity {
private ListView listview;
private Cursor c2;
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 1, "添加").setIcon(R.drawable.a);
menu.add(0, 2, 2, "关于").setIcon(R.drawable.about);
menu.add(0, 3, 3, "退出").setIcon(R.drawable.quite);
menu.add(0, 4, 4, "帮助").setIcon(R.drawable.question);
menu.add(0, 5, 5, "修改密码").setIcon(R.drawable.password);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
Intent intent=new Intent(Main.this,Add.class);
startActivity(intent);
return true;
case 2:
AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
builder.setMessage("作者:康梁 QQ:529667067").setTitle("作者信息")
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
case 3:
AlertDialog.Builder builder3 = new AlertDialog.Builder(Main.this);
builder3.setMessage("确定要退出吗?")
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.exit(0);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert3 = builder3.create();
alert3.show();
return true;
case 4:
AlertDialog.Builder builder2 = new AlertDialog.Builder(Main.this);
builder2.setMessage("请根据日记列表进行操作. 如果没有日记请先添加!"
).setTitle("帮助")
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert2 = builder2.create();
alert2.show();
return true;
case 5:
Intent intent2=new Intent(Main.this,Updatepassword.class);
startActivity(intent2);
return true;
}
return false;
}
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listview=(ListView)findViewById(R.id.listview);
BookBiz bookbiz=new BookBiz(Main.this);
final Cursor c=bookbiz.findall();
show(c);
if(c.getCount()==0){
Toast.makeText(Main.this, "您还没有日记,请按menu键进行添加!", Toast.LENGTH_LONG).show();
}
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
c2=(Cursor)arg0.getItemAtPosition(arg2);
final CharSequence[] items = {"查看", "新建", "删除"};
AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
builder.setTitle("请选择");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog1, int item) {
if(items[item].equals("查看")){
int id3= c2.getInt(0);
Bundle bundle=new Bundle();
bundle.putInt("id", id3);
Intent intent=new Intent(Main.this,Looking.class);
intent.putExtras(bundle);
startActivity(intent);
dialog1.cancel();
}else if(items[item].equals("新建")){
Intent intent=new Intent(Main.this,Add.class);
startActivity(intent);
dialog1.cancel();
}else if(items[item].equals("删除")){
AlertDialog.Builder builder3 = new AlertDialog.Builder(Main.this);
builder3.setMessage("确定要删除吗?")
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog2, int id) {
int id3= c2.getInt(0);
//Toast.makeText(getApplicationContext(), id3, Toast.LENGTH_SHORT).show();
BookBiz book=new BookBiz(Main.this);
book.delete(id3);
Main.this.onCreate(savedInstanceState);
dialog1.cancel();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert3 = builder3.create();
alert3.show();
}
//Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
private void show(Cursor c){
SimpleCursorAdapter adapter=new SimpleCursorAdapter(Main.this, R.layout.listitem, c, new String[]{"title","date"}, new int[]{R.id.xianshititle,R.id.shijian});
listview.setAdapter(adapter);
}
}
Android私密记事本
需积分: 9 87 浏览量
2011-12-22
10:06:43
上传
评论
收藏 340KB RAR 举报
英寒
- 粉丝: 0
- 资源: 1