0

i am trying to pass some values in to a function and compare some values and get the array list.

calling the Collect function in Dbhand class.

        TextView result = (TextView) findViewById(R.id.textviewres);

        result.setText(dbhand.collect(
                getIntent().getExtras().getString("temple_type"), 
                getIntent().getExtras().getString("notemples"))
                );

collect() Function in dbhand class.

public String collect(String temptype, String limit){

    SQLiteDatabase ourDatabase = this.getWritableDatabase();
    String result="";
    String []column =new String[]{KEY_ID,KEY_TMPNAME,KEY_TMPTYPE,KEY_LATITUDE,KEY_LONGITUDE,KEY_IMGNAME,KEY_YEARBUILD,KEY_ADDRESS,KEY_CITY,KEY_EMAIL,KEY_WEB,KEY_TEL1,KEY_TEL2,KEY_DESCRI};
    Cursor c=ourDatabase.query("templ", column, null, null, null, null,null, limit);


    c.moveToFirst();
    int iKEY_ID = c.getColumnIndex(KEY_ID);
    int iKEY_TMPNAME= c.getColumnIndex(KEY_TMPNAME);
    int iKEY_TMPTYPE= c.getColumnIndex(KEY_TMPTYPE);

    for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){

        if (c.getString(iKEY_TMPTYPE) == temptype){

    result = result+c.getString(iKEY_ID)+"\t\t"+c.getString(iKEY_TMPNAME)+"\t\t"+c.getString(iKEY_TMPTYPE)+" \n";
        }
    }

    return result;

}

i didn't get any error, since the if condition is not compared. it does not return any value.

can anyone help me to fix this plz.

Sathya Baman
  • 3,424
  • 7
  • 44
  • 77

3 Answers3

1

This is the bad programming to compare two strings. You should use this.

c.getString(iKEY_TMPTYPE).equalsIgnoreCase(temptype)
Piyush
  • 18,895
  • 5
  • 32
  • 63
0

Use .equals() function of String class to compare Strings.

Like, c.getString(iKEY_TMPTYPE).equals(temptype)

user370305
  • 108,599
  • 23
  • 164
  • 151
0

In your collect method use if (c.getString(iKEY_TMPTYPE).equals(temptype)){

Saurabh Sharma
  • 489
  • 5
  • 20