I ran into the problem of setting text on a TextView
in android, which is my code:
public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button1); final TextView text = (TextView) findViewById(R.id.textView1); final EditText input = (EditText) findViewById(R.id.editText1); final String string = input.getText(); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { text.setText(string); } }); } }
if i write
final Editable string = input.getText();
then it works ..... !!!!
Now I want to send the EditText
data to the following Activity
as follows:
public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button1); final TextView text = (TextView) findViewById(R.id.textView1); final EditText input = (EditText) findViewById(R.id.editText1); final Editable string = input.getText(); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Main.this, Second.class); intent.putExtra("thetext", string); startActivity(intent); } }); } }
and in the Second.java
class Second.java
I get a StringExtra
as follows:
public class Second extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); TextView text = (TextView) findViewById(R.id.textView2); String string = getIntent().getExtras().getString("thetext", "not found"); text.setText(string);
Please give me a way to get started developing.
source share