安卓开发查询mysql数据_安卓入门———简单记账本的开发(三)实现模糊查询,并且实现数据库数据的实时更新...

1 package com.example.hhah;2

3 import java.util.ArrayList;4 import java.util.List;5

6 import android.app.Activity;7 import android.content.res.Resources.NotFoundException;8 import android.database.Cursor;9 import android.database.DatabaseUtils;10 import android.database.sqlite.SQLiteDatabase;11 import android.os.Bundle;12 import android.view.View;13 import android.view.animation.DecelerateInterpolator;14 import android.widget.EditText;15 import android.widget.ListView;16 import android.widget.Toast;17

18 public class query extends Activity {19 private ListView lv;20 private EditText et_things;21 private ArrayListarrayList;22 private MyOpenHelper myOpenHelper;23 private SQLiteDatabase db;24

25 @Override26 protected void onCreate(Bundle savedInstanceState) {27

28 super.onCreate(savedInstanceState);29 setContentView(R.layout.query);30 lv = (ListView) findViewById(R.id.q_lv);31 et_things = (EditText) findViewById(R.id.et_qThings);32 arrayList = new ArrayList();33 myOpenHelper = new MyOpenHelper(getApplicationContext());34

35 }36

37 public void query(View view) {38 String et_things1 = et_things.getText().toString().trim();39 db = myOpenHelper.getWritableDatabase();40 Cursor cursor = db.rawQuery("select * from biao01 where t_name like '%" + et_things1 + "%'", null);41 if (cursor.getCount() == 0) {42 Toast.makeText(getApplicationContext(), "找不到您输入的内容", 1).show();43 } else {44 while (cursor.moveToNext()) {45 int id = cursor.getInt(cursor.getColumnIndex("_id"));46 String t_name = cursor.getString(cursor.getColumnIndex("t_name"));47 String t_place = cursor.getString(cursor.getColumnIndex("t_place"));48 String time = cursor.getString(cursor.getColumnIndex("time"));49 Bean bean = new Bean();50 bean.setT_name(t_name);51 bean.setT_place(t_place);52 bean.setTime(time);53 System.out.println(t_name);54 arrayList.add(bean);55 }56 MyAdapter myAdapter = new MyAdapter(getApplicationContext(), arrayList, R.layout.item);57 lv.setAdapter(myAdapter);58 }59 }60 }

你可能感兴趣的:(安卓开发查询mysql数据)