使用Activity作为对话框

时间:2013-08-12 12:06:08

标签: android android-intent popup

我想要使用弹出窗口。我使用intent编写了一段代码,我希望将其转换为弹出窗口。

这是我的代码:

ArrayList<String> contactList = new ArrayList<String>();

    switch (reqCode) {
    case (0):
        if (resultCode == Activity.RESULT_OK) {
            Uri contactData = data.getData();
            Cursor c = getContentResolver().query(contactData, null, null,
                    null, null);
            if (c.moveToFirst()) {
                String name = c
                        .getString(c
                                .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                String phoneNumber = c
                        .getString(c
                                .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
                String contact = name + phoneNumber;

                contactList.add(contact);
            }
        }
        break;
    }

    Intent intent = new Intent(IndexActivity.this, OrderActivity.class);
    intent.putStringArrayListExtra("Contacts", contactList);
    startActivity(intent);
}

2 个答案:

答案 0 :(得分:1)

以对话框

创建您的活动
<activity
        android:name="OrderActivity"
         android:theme="@android:style/Theme.Dialog"
        android:excludeFromRecents="true" 
        >
    </activity>

并删除活动对话框的标题 - 在setcontentview之前写这个 -

 requestWindowFeature(Window.FEATURE_NO_TITLE);

答案 1 :(得分:0)

    //Below code will help you.. 

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("Contacts");
    builder.setAdapter(new ContactListAdapter(),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    String contact = contactList.get(which);
                    Log.e("onClick", "Selected contact " + contact);
                }
            });

    builder.setNegativeButton("cancel",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    AlertDialog alertDialog = builder.create();

    alertDialog.show();

    Log.d(DEBUG_TAG, "AlertDialog.show");