I am trying to parse a website that searches by content1 or content2 depending which button is clicked. I have an algorithm that works fine, but I was asked to make it in two classes. I hope it’s not gonna make me change my whole algorithm. But yet, I am troubling sending string parameters to the new activity and I hated it.
I defined global parameters:
String content1;
String content2;
I need to get string in an EditText whose names are “namesurname” and “district”:
content1 = district.getText().toString();
content2 = namesurname.getText().toString();
I have two buttons that have listeners:
search1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent search = new Intent(FirstActivity.this, SecondActivity.class);
search.putExtra("param_a", content1);
startActivity(search);
}
});
search2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent search = new Intent(AvukatParserActivity.this, ParserActivity.class);
search.putExtra("param_b", content2);
startActivity(search);
}
});
From now on, my SecondActivity.class shows up.
I am trying to get intent in the new activity:
Intent search = getIntent();
String location = search.getStringExtra("param_a");
String name_surname = search.getStringExtra("param_b");
Here’s how I check my content1:
Toast.makeText(this, location, Toast.LENGTH_LONG).show();
It toastes as null as content2. No errors, no warnings. I don’t get what I’m doing incorrect. Thanks in advance.
each of the listeners put only a single value into the intent instead of both , and the toast shows only one of them .
about this code:
put it inside the onClick methods , and then tell us if it helped .
i’m guessing you put the old values there , so it gets null instead of the updated values.