警报对话框中的多个选择

时间:2016-04-20 03:18:14

标签: android facebook-android-sdk android-dialog android-sdk-2.3

美好的一天,

我创建了一个方法showDialog,它将显示一个Alert Dialog并列出我可以选择的多个数据。我的问题是当我单击OK时,我想调用的下一个方法(myMethod())没有被调用。有人可以帮我弄这个吗?这是我的代码:

private void showDialog(List<String> list) {
    final CharSequence[] dialogList=  list.toArray(new CharSequence[list.size()]);
    final AlertDialog.Builder builderDialog = new AlertDialog.Builder(SharingActivity.this);
    builderDialog.setTitle("Select Item");
    int count = dialogList.length;
    boolean[] is_checked = new boolean[count];
    String result = "";

    builderDialog.setMultiChoiceItems(dialogList, is_checked,
            new DialogInterface.OnMultiChoiceClickListener() {
                public void onClick(DialogInterface dialog,
                                    int whichButton, boolean isChecked) {
                }
            });

    builderDialog.setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    ListView list = ((AlertDialog) dialog).getListView();
                    // make selected item in the comma seprated string
                    StringBuilder stringBuilder = new StringBuilder();
                    for (int i = 0; i < list.getCount(); i++) {
                        boolean checked = list.isItemChecked(i);

                        if (checked) {
                            if (stringBuilder.length() > 0) stringBuilder.append(",");
                            stringBuilder.append(list.getItemAtPosition(i));

                        }
                    }

                    myMethod(stringBuilder.toString()); //this is the method

                }
            });

    builderDialog.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ((TextView) findViewById(R.id.text)).setText("Click here to open Dialog");
                }
            });
    AlertDialog alert = builderDialog.create();
    alert.show();
}

这是myMethod:

private void myMethod(String stringFriend){
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("image");

Bitmap image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
//Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .setCaption("")
        .build();
List<String> peopleIds =  new ArrayList<String>();
peopleIds.add(stringFriend);

SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .setPeopleIds(peopleIds)
        .build();

ShareApi.share(content, null);

}

0 个答案:

没有答案