I need the string from EditText from Mainactivity so that i can compare the value and show the desired image in the next..but only the else part is working in the second activity. I tried this code but it did't work..
private Button b1;
static EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText)findViewById(R.id.pass);
b1 = (Button)findViewById(R.id.clickhere);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(et.getText().toString().equals(getString(R.string.Ronnie)))
{
Intent myIntent = new Intent(MainActivity.this,
Thought.class);
startActivity(myIntent);
}
else if(et.getText().toString().equals(getString(R.string.Ankita)))
{
Intent myIntent = new Intent(MainActivity.this, Thought.class);
startActivity(myIntent);
}
else
{
Toast.makeText(getApplicationContext(),"Not for you",Toast.LENGTH_SHORT);
}
}
});
}
and second activity code
public class Thought extends MainActivity {
public ImageView iv;
static String s1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
setContentView(R.layout.activity_thought);
s1 = MainActivity.et.getText().toString();
iv = (ImageView)findViewById(R.id.imageView);
if(s1.equals(getString(R.string.Ronnie)))
{
iv.setImageResource(R.drawable.ronniel);
}
else if(s1.equals(getString(R.string.Ankita)))
{
iv.setImageResource(R.drawable.ankitat);
}
else
{
iv.setImageResource(R.drawable.subha);
}
}
}