提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
一、首先创建保存数据的表
Notedatabase,java文章来源:https://www.toymoban.com/news/detail-470553.html
package com.example.biji_1;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class NoteDatabase extends SQLiteOpenHelper {
public static final String TABLE_NAME ="notes";
public static final String CONTENT ="content";
public static final String ID ="_id";
public static final String TIME ="time";
public static final String MODE ="mode";
public NoteDatabase(Context context){
super(context,"notes",null,1);
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + TABLE_NAME + "(" + ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ CONTENT + " TEXT NOT NULL, "
+ TIME + " TEXT NOT NULL, "
+ MODE + " INTEGER DEFAULT 1)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,int newVersion){
}
}
二、主界面
MainAcitivity.java文章来源地址https://www.toymoban.com/news/detail-470553.html
public class MainActivity extends BaseActivity implements AdapterView.OnItemClickListener {
//test gittt
private NoteDatabase dbHelper;
private Context context = this;
final String TAG = "tag";
FloatingActionButton btn;
private ListView lv;
private NoteAdapter adapter;
private List<Note> noteList = new ArrayList<Note>();
private Toolbar myToolbar;
//弹出菜单
private PopupWindow popupWindow;
private PopupWindow popupCover;
private ViewGroup customView;
private ViewGroup coverView;
private LayoutInflater layoutInflater;
private RelativeLayout main;
private WindowManager wm;
private DisplayMetrics metrics;
private TextView setting_text;
private ImageView setting_image;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initPrefs();
btn = (FloatingActionButton) findViewById(R.id.fab);
lv = findViewById(R.id.lv);
myToolbar = findViewById(R.id.myToolbar);
adapter = new NoteAdapter(getApplicationContext(), noteList);
refreshListView();
lv.setAdapter(adapter);
setSupportActionBar(myToolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //设置toolbar取代actionbar
initPopUpView();
myToolbar.setNavigationIcon(R.drawable.ic_baseline_menu_24);
myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: shit");
showPopUpView();
}
});
lv.setOnItemClickListener(this);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra("mode", 4);
startActivityForResult(intent, 0);
}
});
}
public void initPopUpView(){
layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
customView = (ViewGroup) layoutInflater.inflate(R.layout.setting_layout, null);
coverView = (ViewGroup) layoutInflater.inflate(R.layout.setting_cover, null);
main = findViewById(R.id.main_layout);
wm = getWindowManager();
metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
}
public void showPopUpView(){
int width = metrics.widthPixels;
int height = metrics.heightPixels;
popupCover = new PopupWindow(coverView, width, height, false);
popupWindow = new PopupWindow(customView, (int) (width
到了这里,关于Android安卓备忘录(笔记)大作业简单实现有源码注释详细的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!