Can I compare the data from getStringExtra() with a string?
Sample code:
Intent intent = getIntent();
String path = intent.getStringExtra("category");
if(path == "car"){
setListAdapter(new ArrayAdapter<String>(this, R.layout.subcategory, car));
} else {
setListAdapter(new ArrayAdapter<String>(this, R.layout.subcategory, bike));
}
Why is the script is not running?
When comparing two strings to check if they are equal in java you should use equals().
In your case you should change your comparison line to
if(path.equals("car"))
In java the equals() compares the actual contents of your strings while == will only compare to see if the two references are equal
use
path.equals("car") "or"
path.contains("car") "or"
path.equalsIgnoreCase("car") "or"
as this is more precise
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With