[英]Cannot make a static reference to the non-static method show(FragmentManager, String) from the type DialogFragment
Hey Guys i'm having a few issues with I think importation. 嗨,我在输入方面遇到一些问题。 I'm getting the error message in the title under
MyDialog.show(manager, "MyDialog");
我在
MyDialog.show(manager, "MyDialog");
下的标题中收到错误消息MyDialog.show(manager, "MyDialog");
Anybody know what it means? 有人知道这是什么意思吗? I'm thinking some issue with importing but i'm not to sure.
我在考虑导入方面的问题,但不确定。
Rest of code: 其余代码:
package com.example.sub_assignment1_2;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
/**
* A simple {@link Fragment} subclass.
*
*/
public class FragmentB extends Fragment implements MyDialog.Communicator {
public FragmentB() {
// Required empty public constructor
}
public void showDialog(View v)
{
FragmentManager manager=getFragmentManager();
MyDialog myDialog=new MyDialog();
MyDialog.show(manager, "MyDialog");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_b, container, false);
}
@Override
public void onDialogMessage(String message) {
Toast.makeText(this, message,Toast.LENGTH_SHORT).show();
}
}
I'm also having an issue under Toast.makeText(this, message,Toast.LENGTH_SHORT).show();
我在
Toast.makeText(this, message,Toast.LENGTH_SHORT).show();
下也遇到问题 The displayed error is: Toast.makeText(this, message,Toast.LENGTH_SHORT).show();
显示的错误是:
Toast.makeText(this, message,Toast.LENGTH_SHORT).show();
Which i'm also thinking is an import error? 我还在想哪个是导入错误?
If anybody could help that would be great. 如果有人可以帮助,那就太好了。
In MyDialog.show(manager, "MyDialog");
在
MyDialog.show(manager, "MyDialog");
should you not have myDialog.show - ie the instance not the class? 您应该没有myDialog.show-即实例而不是类吗? Calling the method on the class name would be a static reference, which doesn't require an instance.
在类名上调用该方法将是一个静态引用,不需要实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.