title: How to search through a DB using a cursor( sqlite query) in android
body: <p>I am an android beginner. I am trying to design this simple application which takes the name of a city from the user using an editText View , compares that in the database , and returns the ZIP code of that city. 
  Now ,I'm having a problem with the implementation of cursors. Please help.How can i query the database to fetch the corresponding code.</p>
  
  <pre><code>        EditText city;
      Button add,show1;
      RadioGroup choose;
      String k;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          try
          {   
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          //final ContentValues values = new ContentValues();
          city=(EditText)findViewById(R.id.editText1);
          add=(Button)findViewById(R.id.add);
          choose=(RadioGroup)findViewById(R.id.radio01);
          show1=(Button)findViewById(R.id.button1);
          k=city.getText().toString();
          createDatabase();
      }
          catch(Exception e)
          {
  
          }
  
  
  show1.setOnClickListener(new View.OnClickListener() {
  
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
          db=openOrCreateDatabase(DATABASE_NAME,Context.MODE_PRIVATE,null);
          try{
  
          if(k == "CITY")
          {
              String[] result_columns=new String[]{"_id","CITY","CODE"};
              Cursor cursor = db.query(TABLE_NAME, result_columns, 
                      "CITY" +"=?", new String[]{"k"}, null, null, null);
  
      cursor.moveToFirst();
  
          String xnewcode=cursor.getString(0);
          Toast.makeText(activity1.this, xnewcode, Toast.LENGTH_LONG).show();
          cursor.moveToNext();
  
              //db.close();
          }}
          catch(Exception e)
          {
              Toast.makeText(activity1.this,"Fault in showing " + e,Toast.LENGTH_LONG).show();
  
          }
  
      }
  
  });
  </code></pre>