我正在尝试将数据从对话框传递到新的活动。因此,基本上,我想在对话框中做的事情是,例如,我有Name: John
,当我单击“确定”按钮时,它将打开一个新活动,但我希望在我的{{1 }}关于我的新活动:
这是我的活动,其中我的对话框代码为:
John
所以我想将edit box
传递给新活动:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/** To change selected state view */
view.setSelected(true);
HashMap<String, Object> obj = (HashMap<String, Object>) ADAhere.getItem(position);
String SlectedName = (String) obj.get("NAME");
String SlectedPrice = (String) obj.get("PRICE");
String SlectedSize = (String) obj.get("SIZE");
String SlectedRange = (String) obj.get("RANGE");
String SlectedSupp = (String) obj.get("SUPPLIER");
// Toast.makeText(getActivity().getApplicationContext(), SlectedName, Toast.LENGTH_SHORT).show();
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow();
//dialog.setTitle("Confirm your Vote");
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.diaglog);
final TextView VName = (TextView) dialog.findViewById(R.id.Name);
final TextView VRange = (TextView) dialog.findViewById(R.id.Range);
final TextView VSUPPLIER = (TextView) dialog.findViewById(R.id.Supplier);
final TextView VSIZE = (TextView) dialog.findViewById(R.id.Size);
final TextView VPrice = (TextView) dialog.findViewById(R.id.Price);
VName.setText(SlectedName);
VRange.setText(SlectedRange);
VSUPPLIER.setText(SlectedSupp);
VSIZE.setText(SlectedSize);
VPrice.setText(SlectedPrice);
dialog.show();
Button cancelBtn = (Button) dialog.findViewById(R.id.cancel_btn);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
Button UpdateBtn = (Button) dialog.findViewById(R.id.btn_update);
UpdateBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);
}
});
Button deleteBtn = (Button) dialog.findViewById(R.id.btn_delete);
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);
}
});
dialog.show();
}
});
答案 0 :(得分:3)
额外输入:
代替:
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);
您应该输入名称
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
i.putExtra("string", SlectedName);
startActivity(i);
然后,在您的Upvalence活动中:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Bundle arguments = this.getIntent().getExtras();
String yourString = arguments.getString("string");
}