我可以从活动一中获取文本,如何获取文本并粘贴到我的 URL 中?
活动一
public class MainActivity extends Activity {
private Button tombol;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tombol=(Button)findViewById(R.id.button1);
tombol.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
startActivityForResult(intent, 0);
}
});
活动二
EditText et;
ImageView iv;
public Button tombol;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
loadGambar();
private void loadGambar(){
try {
iv = (ImageView) findViewById(R.id.imageView1);
et = (EditText) findViewById(R.id.editText1);
tombol = (Button) findViewById(R.id.button1);
URL url = new URL (et.getText().toString());
InputStream is = (InputStream) url.getContent();
Drawable gambar = Drawable.createFromStream(is, "src");
iv.setImageDrawable(gambar);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
tombol=(Button)findViewById(R.id.button1);
tombol.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}
}
单击按钮后我可以从编辑文本中获取文本,如何解决?
我准备尝试使用 StartActivity,我只想将该文本粘贴到活动 2 中
URL url = 新 URL (et.getText().toString());