Here is my problem. I can't assign new value of parameter after comparison of another object's parameters with database object's parameters. I need to assign new value of test_car.make or make . It seems, that XML code is fine, so the problem should be in that code. Here is my code:
package com.j.caradvisor;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.j.models.Car;
public class Result extends AppCompatActivity {
int i=0;
int doors;
String make;
String model;
String layout;
String trunk;
String gearbox;
int price;
int expeople;
Car test_car = new Car(1, "testmake", "testmodel", "test_layuot", "testtrunk", "testgearbox", 1, 1);
String final_car=make+""+model;
TextView resultt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
resultt = (TextView) findViewById(R.id.result);
test_car = getIntent().getParcelableExtra("test_car");
doors = test_car.getDoors();
make = test_car.getMake();
model = test_car.getModel();
trunk = test_car.getTrunk();
gearbox = test_car.getGearbox();
price = test_car.getPrice();
expeople = test_car.getExpeople();
this.getPackageName();
//resultt.setText(final_car);
}
public void data(View view) {
Car[] car;
car = new Car[12];
car[0] = new Car(4, "Volkswagen", "Passat", "4 door saloon", "Spacious", "Both", 25000, 5);
car[1] = new Car(2, "Mazda", "MX-5", "Roadster", "Small", "Both", 20000, 2);
car[2] = new Car(2, "BMW", "2 series", "2 door coupe", "Spacious", "Both", 20000, 4);
car[3] = new Car(3, "Volkswagen", "Golf", "3 door hatchback", "Spacious", "Both", 20000, 4);
car[4] = new Car(5, "Peugeot", "308", "5 door hatchback", "Spacious", "Both", 20000, 5);
car[5] = new Car(5, "Peugeot","508","Estate", "Spacious", "Both", 25000, 5);
car[6] = new Car(5, "Ford", "S-Max", "Minivan", "Spacious", "Both", 28000,7);
car[7] = new Car(5, "Ford", "Transit", "Van", "Spacious", "Manual", 20000, 9);
car[8] = new Car(3, "Jeep", "Wrangler", "3 door SUV", "Spacious", "Automatic", 40000, 4);
car[9] = new Car(5, "KIA", "Sportage", "5 door SUV", "Spacious", "Both", 25000, 5);
car[10] = new Car(4, "Audi", "A7", "4 door coupe", "Spacious", "Both", 60000, 4);
car[11] = new Car(5, "Peugeot", "208", "5 door hatchback", "Small", "Both", 14000, 5);
for (Car aCar : car) {
if ((test_car.getDoors() == aCar.getDoors())
&& (test_car.getLayout().equals(aCar.getLayout()))
&& (test_car.getTrunk().equals(aCar.getTrunk()))
&& (test_car.getGearbox().equals(aCar.getGearbox()))
&& (test_car.getPrice() <= aCar.getPrice())
&& (test_car.getExpeople() <= aCar.getExpeople())) {
test_car.setMake(aCar.getMake());
make = test_car.getMake();
//model=car[i].getModel();
//test_car.setMake(make);
//test_car.setModel(model);
//resultt.setText(make);
//resultt.setText(test_car.getMake());
}
}
//resultt.setText(test_car.getMake());
resultt.setText(make);
}
public void map_search(View view) {
String uri = "http://maps.google.com/maps?saddr=" +test_car.getMake();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
}
}
if ((test_car.getDoors() == aCar.getDoors())
It seems to always be returning false since your test car is set to 1 (I am assuming car[0] is the doors) so
test_car.setMake(aCar.getMake()); make = test_car.getMake();`
Never runs, this also depends on what you're giving as the intents ParcableExtra
test_car = getIntent().getParcelableExtra("test_car");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.