Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xx.x;
- import android.app.Activity;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteException;
- import android.os.Bundle;
- import android.text.Editable;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class XActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- final TextView t = (TextView) findViewById(R.id.tv);
- final Button s = (Button) findViewById(R.id.button1);
- final EditText et = (EditText) findViewById(R.id.et);
- s.setOnClickListener(new OnClickListener() {
- public void onClick(View arg) {
- // TODO Auto-generated method stub
- String ee = et.getText().toString();
- //Code for database
- SQLiteDatabase db;
- try{
- db = SQLiteDatabase.openDatabase("data/data/xx.x/databases/dictionary", null,0);
- String q = "SELECT * FROM LIST where( wlist like '"+ee+"%')"+"ORDER BY wlist";
- Cursor c = db.rawQuery(q, null);
- if(c.getCount() == 0)
- {
- t.setText("Not found1");
- }
- else {
- String j="";
- c.moveToFirst();
- do {
- String cm = c.getString(c.getColumnIndex("wlist"));
- j = j+"\n"+cm;
- } while (c.moveToNext());
- t.setText(j);
- c.close();
- db.close();
- }
- }
- catch(SQLiteException e){
- db = openOrCreateDatabase("dictionary", MODE_PRIVATE, null);
- db.execSQL("CREATE TABLE IF NOT EXISTS LIST(wlist varchar);");
- db.execSQL("INSERT INTO LIST VALUES('add');");
- db.execSQL("INSERT INTO LIST VALUES('imran');");
- db.execSQL("INSERT INTO LIST VALUES('rana');");
- db.execSQL("INSERT INTO LIST VALUES('role');");
- String q = "SELECT * FROM LIST where( wlist like '"+ee+"%')"+"ORDER BY wlist";
- Cursor c = db.rawQuery(q, null);
- if(c.getCount() == 0)
- {
- t.setText("Not found2");
- }
- else {
- String j="";
- c.moveToFirst();
- do {
- String cm = c.getString(c.getColumnIndex("wlist"));
- j = j+"\n"+cm;
- } while (c.moveToNext());
- t.setText(j);
- c.close();
- db.close();
- }
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement