Java Android AlertDialog如何传递参数

Java Android AlertDialog如何传递参数,java,android,android-alertdialog,args,Java,Android,Android Alertdialog,Args,在“自定义适配器”的代码中,我有活动A(它有Listview的自定义适配器),我想调用AlertDialog,它将显示第二个活动(活动B) 我可以完美地显示活动,但我想知道如何在活动A和活动B之间传递args CustomAdapter.java: view_details.setClickable(true); view_details.setOnClickListener(new OnClickListener() { @Override public void onCli

在“自定义适配器”的代码中,我有活动A(它有Listview的自定义适配器),我想调用AlertDialog,它将显示第二个活动(活动B)

我可以完美地显示活动,但我想知道如何在活动A和活动B之间传递args

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()”下面:

但是没有起作用。然后我考虑使用“Bundle”在活动之间传递参数。因此,在“alertD.show()”之后:

也没用。 使用最后一段代码,我没有收到任何错误,但它也不显示信息。使用“setText”时,我收到一个NullPointerException错误(就像活动没有初始化然后检索错误一样)

谢谢

已解决

我对AlertDialog的观点是要有这样的窗口。我发现我们可以在主题中设置这种类型的窗口(对话框)。因此,现在一切都变得容易和可能

// styles.xml
<style name="MyTheme" parent="android:style/Theme.Dialog">
       <item name="android:windowNoTitle">true</item>
</style>
<-------------->
// Manifest.xml
<activity
    android:name="com.example.MyExample.activity_B"
    android:label="@string/activity_B"
    android:windowSoftInputMode="stateHidden" 
    android:theme="@style/MyTheme">
</activity>
谢谢。

试试这个-

String title1 = this is the title;
Intent i = new Intent(context, activityB.class);
i.putExtra("title", title1);
然后从你的新活动中提取它-

Intent intent = getIntent();
String title1 = intent.getExtras.getString("title");

问题不清楚,也张贴日志i.putExtra(“标题”,“这就是标题”);你写两个括号。也许是你没有收到任何东西的原因。
Intent i = new Intent(getContext(), activity_B.class);
i.putExtra("field", "value");
context.startActivity(i);
String title1 = this is the title;
Intent i = new Intent(context, activityB.class);
i.putExtra("title", title1);
Intent intent = getIntent();
String title1 = intent.getExtras.getString("title");