java - 无法解析构造函数 ArrayAdapter(android.Content.Context, int, java.util.ArrayList<MyObject>)

标签 java android android-arrayadapter

我知道这个问题之前已经被问过一百万次了,但我已经尝试了所有我能找到的解决方案,但仍然不起作用。我尝试过调用“this”作为上下文,我尝试过 getActivity,我尝试过 getContext(),但似乎没有什么特别适合这个 fragment 。相同的代码确实可以在不同的 fragment 中工作,这就是为什么我真的很困惑。任何帮助表示赞赏。

我的LoginFragment,我的问题可以在setReservations()中找到:

public class LoginFragment extends Fragment {
    LoginButton loginButton;
    TextView nameText;
    ProfileTracker mProfileTracker;
    DBHandler dbHandler;
    Context context;
    ArrayList<Reservation> reservations;
    ListView lv;
    Profile fbProfile;

    CallbackManager callbackManager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.login, container, false);
        callbackManager = CallbackManager.Factory.create();
        dbHandler = new DBHandler(getContext(), null, null, 1);
        context = getActivity();
        loginButton = (LoginButton) view.findViewById(R.id.login_button);
        nameText = (TextView) view.findViewById(R.id.users_name);
        loginButton.setReadPermissions("email");
        setmProfileTracker();
        mProfileTracker.startTracking();
        // If using in a fragment
        loginButton.setFragment(this);
        // Other app specific specialization

        // Callback registration
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

            }

            @Override
            public void onCancel() {
                // App code
            }

            @Override
            public void onError(FacebookException exception) {
                // App code
            }
        });

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        fbProfile = Profile.getCurrentProfile();
        if (fbProfile != null)
        {
            updateUI();
        }
        getActivity().setTitle("My page");
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode,resultCode,data);
    }

    private void setmProfileTracker()
    {
        mProfileTracker = new ProfileTracker() {
            @Override
            protected void onCurrentProfileChanged(Profile profile, Profile profile2) {
                updateUI(); //this is the third piece of code I will discuss below
            }
        };
    }

    private void updateUI() {

        boolean enableButtons = AccessToken.getCurrentAccessToken() != null;
        if (fbProfile == null) {
            fbProfile = Profile.getCurrentProfile();
            Log.e("Profile", "null");
        }
        if (enableButtons && fbProfile != null) {
            Log.e("Access Token", AccessToken.getCurrentAccessToken().toString());
            nameText.setText(fbProfile.getName());
        }
    }

    private void setReservations()
    {
        reservations = dbHandler.userReservationToArrayList(parseLong(fbProfile.getId()));

        lv = (ListView) getView().findViewById(R.id.reservations);

        ArrayAdapter<Review> arrayAdapter = new ArrayAdapter<Review>(
            context,
            android.R.layout.simple_list_item_1,
            reservations);

        lv.setAdapter(arrayAdapter);
    }
}

编辑:代码格式

最佳答案

您的阵列适配器属于类型审查

ArrayAdapter<Review> arrayAdapter 

但是你的过世:

 ArrayList<Reservation> reservations
Change it to ArrayAdapter<Reservation>

关于java - 无法解析构造函数 ArrayAdapter(android.Content.Context, int, java.util.ArrayList<MyObject>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44178693/

相关文章:

java - 使用 Java 和 iText 创建百分比栏

java - 显示图像列表时出现应用程序小部件问题

android - boolean 值从一开始就设置为 true

android - Cordova 运行安卓 : ANDROID_HOME not set and android not in my path

Android,webview 用户代理与浏览器用户代理

android-arrayadapter - 如何使用 Leanback 库在 Android TV 中高效实现大型单个列表

java - 如何在jmockit中生成coverage.xml?

android - 数组适配器中的反向列表顺序

android - ArrayAdapter 线程在 android 中安全吗?如果不是,我该怎么做才能使其线程安全?

java - 使用文件类和 FileOutputStream 创建文件有什么区别?