我有活动 A(具有 Listview 的自定义适配器),在“自定义适配器”的代码中,我想调用 AlertDialog,它将向我显示第二个活动(活动 B)。
我可以完美地展示活动,但我想知道如何在活动 A 和活动 B 之间传递参数?
CustomAdapter.java:
view_details.setClickable(true);
view_details.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View promptView = layoutInflater.inflate(R.layout.activity_activity_B, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setView(promptView);
AlertDialog alertD = alertDialogBuilder.create();
alertD.show();
首先,我只想将以下代码放在“alertD.show()”下面:
TextView title_ = (TextView) v.findViewById(R.id.title_B); // Activity B
title_.setText("Example");
但是没有用。然后我考虑使用“Bundle”在活动之间传递参数。所以,再次,在“alertD.show()”之后:
Intent i = new Intent(context, activityB.class);
i.putExtra("title", "this is the title"));
// And get this way in ActivityB:
// Bundle extras = getIntent().getExtras();
// String g = extras.getString("title");
也没有工作。使用最后一个代码,我没有收到任何错误,但它也不显示信息。使用“setText”我收到 NullPointerException 错误(就像,活动没有初始化然后它检索错误。)
谢谢。