请登录后探索更多精彩内容!
接下来查看和查询笔记功能,当用户选择某一条记事,再点击查看跳转到另一个界面可以查看该记事的完整信息。当用户想搜索某条记事时可通过关键字查询,我这里用的数据库查询语句不太好,应该使用模糊查询更好一点。
查看记事功能的实现代码
package com.example.notebook; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.EditText; import android.widget.TextView; /*----------------------------------查看功能------------------------------------*/ public class CheakActivity extends Activity { //定义几个标签 private TextView titleTextView,dateTextView,contentTextView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cheak); //绑定组件 titleTextView=(TextView)findViewById(R.id.listview_tvtitle); dateTextView=(TextView)findViewById(R.id.cheak_tvdate); contentTextView=(TextView)findViewById(R.id.cheak_tvcontent); //接收传输过来的信息 Intent intent=getIntent(); Bundle bundle=intent.getExtras(); Notelist notelist=(Notelist)bundle.getSerializable("note"); //将传输过来的信息分别赋值给几个标签 titleTextView.setText(notelist.getTitleString()); dateTextView.setText(notelist.getDateString()); contentTextView.setText(notelist.getEventString()); } }
查询记事功能的实现代码
package com.example.notebook; import java.util.ArrayList; import java.util.List; import com.example.notebook.NoteActivity.Myadapter; import android.database.Cursor; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; /*----------------------------------查询功能------------------------------------*/ public class SearchActivity extends MainActivity { private Button searchbuttton; private EditText searchEditText; private ListView rsListView; private List<Notelist> rslist= new ArrayList<Notelist>(); private shadapter rsAdapter=null; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); searchbuttton=(Button)findViewById(R.id.search_btnsh); searchEditText=(EditText)findViewById(R.id.search_edtsh); rsListView=(ListView)findViewById(R.id.search_lvsh); /*----------------------------------查询按钮监听------------------------------------*/ searchbuttton.setOnClickListener(new OnClickListener() { public void onClick(View v) { MydatabaseHelper mydatabaseHelper=new MydatabaseHelper(SearchActivity.this); mydatabaseHelper.getWritableDatabase(); Cursor result=mydatabaseHelper.findnoteCursor(); for (result.moveToFirst();!result.isAfterLast();result.moveToNext()) { Notelist rslists= new Notelist(result.getInt(0),result.getString(1),result.getString(2),result.getString(3)); //如果输入数据与数据库内容匹配成功就显示在listview if (searchEditText.getText().toString().equals(result.getString(1))) { rslist.clear(); rsAdapter.notifyDataSetChanged(); rslist.add(rslists); } } } }); rsAdapter = new shadapter(); rsListView.setAdapter(rsAdapter); } /*----------------------------------自定义适配器------------------------------------*/ class shadapter extends BaseAdapter{ public int getCount() { return rslist.size(); } public Object getItem(int arg0) { return rslist.get(arg0); } public long getItemId(int arg0) { return arg0; } public View getView(int arg0, View arg1, ViewGroup arg2) { View myView=null; myView=arg1.inflate(SearchActivity.this, R.layout.activity_note, null); TextView ttTextView=(TextView)myView.findViewById(R.id.note_notename); TextView dtTextView=(TextView)myView.findViewById(R.id.note_notetime); ttTextView.setText(rslist.get(arg0).getTitleString()); dtTextView.setText(rslist.get(arg0).getDateString()); return myView; } } }
暂无评论
请先登录后发表评论!
暂无评论