here is the code from 1st activity:
package com.android.shopping;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
Button btn;
ListView lista;
TextView tekst;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button) findViewById(R.id.button1);
lista=(ListView) findViewById(R.id.listView1);
btn.setOnClickListener(this);
tekst=(TextView) findViewById(R.id.textView1);
}
@Override
public void onClick(View v) {
Intent i=new Intent(this, DetailsActivity.class);
startActivityForResult(i, RESULT_OK);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
String item=data.getStringExtra("data").toString();
tekst.setText(item.toString());
}
}
}
And the second one:
package com.android.shopping;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class DetailsActivity extends Activity implements OnClickListener{
Button save;
EditText details;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
save=(Button) findViewById(R.id.button1);
details=(EditText) findViewById(R.id.editText1);
save.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent in=new Intent();
in.putExtra("data", details.getText().toString());
setResult(RESULT_OK, in);
finish();
}
}
So in the first activity with the button I call the second activity. There user types in something in a textfield and click a button which brings him back to the first activity. And there the text he had typed should be shown in the textView from the first activity, but it is not. Please help me fix that.