我可以从活动1获取文字,如何获取文字并粘贴到我的网址中?
活动一
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,我只想将该文本粘贴到活动二内嵌
网址url =新网址(et.getText()。toString());
答案 0 :(得分:0)
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
intent.putExtra("URL", yoururlstring);
startActivityForResult(intent, 0);
}
});
在活动一中使用上述代码将值从一个活动传递到其他
在活动2中获取sring使用
String url= getIntent().getExtras().getString("URL");