我如何在同一活动中传递字符串?我有很多按钮,所以我在 open() 中使用了 getstring ???。所有在同一个活动中......在这个活动中,我已经使用来自另一个活动的意图传递字符串。
View view1 = findViewById(R.id.v1);
view1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle i = new Bundle();
i.putString("key1", title1); // Key1
i.putString("key2", link1); // Key2
open();
}
});
View viewnowvideo= findViewById(R.id.tvnowvideo);
viewnowvideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle i = new Bundle();
i.putString("key1", title2); // Key1
i.putString("key2", link2); // Key2
open();
}
});
}
private void open() {
Bundle i = new Bundle();
String titleok = i.getString("key1"); //// Key1
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setTitle(titleok);
dialog.setContentView(R.layout.popup);
Button button = (Button) dialog.findViewById(R.id.open2);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Bundle i = new Bundle();
String linkok = i.getString("key2"); //// Key2
Uri location = Uri.parse(linkok);
Intent intent = new Intent(Intent.ACTION_VIEW, location);
intent.setPackage("com.dfgfdg.dfgdfg");
startActivity(intent);
}
});
}