片段中的Intent和AlertDialog无法正常工作

时间:2015-08-16 13:26:57

标签: android if-statement android-fragments android-intent android-alertdialog

我有一个片段有一些图片,你选择一张图片,然后按下一个去另一个班级选择朋友。

如果您不选择图片,我想显示一个警告对话框,否则他们应该选择朋友。

protected TextView mMessage;
mMessage = (TextView) view.findViewById(R.id.Text);
final String userMessage = mMessage.getText().toString();

mNext = (Button) view.findViewById(R.id.nextButton);
mNext.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (userMessage.equals("") || userMessage.equals(null)) { 
            AlertDialog.Builder builder = new AlertDialog.Builder(messageFragment.this.getActivity());
            builder.setTitle("oops");
            builder.setMessage("Make sure you take a pic");
            builder.setPositiveButton(android.R.string.ok, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        } else {
            //blahh
        }
    }
});

即使我在文本视图中有文本,也会显示警告对话框。

1 个答案:

答案 0 :(得分:0)

Inside Fragments使用getActivity()不是这个。

试试这个;

Applying: commitmessage
error: patch failed: filename:387
error: filename: patch does not apply
Patch failed at 0001 commitmessage
The copy of the patch that failed is found in:
   /home/username/www/mycode/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".