回收站视图:未连接适配器;跳过布局

时间:2019-06-24 04:22:20

标签: android android-recyclerview xampp

我正在使用 xampp 设计社交媒体应用。我在应用程序中设计了底部导航,并在登录后使用firebase登录到google,这样设置了个人资料活动,用户名和个人资料仅通过google登录即可显示在此处。但是有些方法并没有在其中显示名称和个人资料图片,所有代码都运行良好,但不知道我在哪里得到错误。

个人资料activity.java

package com.example.friendster.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.friendster.R;
import com.example.friendster.adapter.ProfileViewPagerAdapter;
import com.example.friendster.model.User;
import com.example.friendster.rest.ApiClient;
import com.example.friendster.rest.services.UserInterface;
import com.google.firebase.auth.FirebaseAuth;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;




public class ProfileActivity extends AppCompatActivity {

    @BindView(R.id.profile_cover)
    ImageView profileCover;
    @BindView(R.id.profile_image)
    CircleImageView profileImage;
    @BindView(R.id.profile_option_btn)
    Button profileOptionBtn;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.collapsing_toolbar)
    CollapsingToolbarLayout collapsingToolbar;
    @BindView(R.id.ViewPager_profile)
    ViewPager ViewPagerProfile;

    ProfileViewPagerAdapter profileViewPagerAdapter;


    /*
    0 = profile still loading
    1 = two people are friends (unfriend)
    2 = this person has sent friend request to another friend ( cancel sent request)
    3 = this has rcvd frnd rqst frm another frnd (rjct or accpt rqst)
    4 = people are unknown (you can send rqst)
    5 = own profile
    */

    int  current_state=0;
    String profileUrl="",coverUrl="";

    String uid ="0";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //for hiding status bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_profile);

        uid = getIntent().getStringExtra("uid");
       // Log.d("CHECKVALUE",uid);
        //Log.d("CHECKVALUE",FirebaseAuth.getInstance().getCurrentUser().getUid()+"");

        ButterKnife.bind(this);

        profileViewPagerAdapter =new ProfileViewPagerAdapter(getSupportFragmentManager(),  1);

        //adding back buttn
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.arrow_back_white);

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ProfileActivity.this,MainActivity.class));
            }
        });

        ViewPagerProfile.setAdapter(profileViewPagerAdapter);

        if (FirebaseAuth.getInstance().getCurrentUser().getUid().equalsIgnoreCase(uid)) {
            //UID is matchedd ,we are going to load own profile

            current_state=5;
            profileOptionBtn.setText("Edit Profile");
           // loadProfile();
        }else{

            //load other profile here
        }
    }

   private void loadProfile() {
        UserInterface userInterface = ApiClient.getApiClient().create(UserInterface.class);
        Map<String, String> params =new HashMap<>();
        params.put("userId",FirebaseAuth.getInstance().getCurrentUser().getUid());
        Call<User> call = userInterface.loadownProfile(params);
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                if (response.body()!=null) {
                    profileUrl = response.body().getProfileUrl();
                    coverUrl = response.body().getCoverUrl();
                    collapsingToolbar.setTitle(response.body().getName());

                    if (!profileUrl.isEmpty()) {
                        Picasso.with(ProfileActivity.this).load(profileUrl).networkPolicy(NetworkPolicy.OFFLINE).into(profileImage, new com.squareup.picasso.Callback() {

                            @Override
                            public void onSuccess() {

                            }

                            @Override
                            public void onError() {

                                Picasso.with(ProfileActivity.this).load(profileUrl).into(profileImage);
                            }
                        });

                        if (!coverUrl.isEmpty()) {
                            Picasso.with(ProfileActivity.this).load(coverUrl).networkPolicy(NetworkPolicy.OFFLINE).into(profileCover, new com.squareup.picasso.Callback() {

                                @Override
                                public void onSuccess() {

                                }

                                @Override
                                public void onError() {

                                    Picasso.with(ProfileActivity.this).load(coverUrl).into(profileCover);
                                }
                            });
                        }
                    }

                }else {
                    Toast.makeText(ProfileActivity.this, "Something went wrong... please try later",Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {
                Toast.makeText(ProfileActivity.this, "Something went wrong... please try later",Toast.LENGTH_SHORT).show();


            }
        });
    }
}

fragment_profile.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">




    <android.support.v7.widget.RecyclerView
        android:id="@+id/memories_recy"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background= "#DCDEE3"
        android:layout_above="@id/feedProgressBar" />

    <ProgressBar
        android:id="@+id/feedProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom|center"
        android:visibility="gone" />

</RelativeLayout>

ProfileViewPagerAdapter.java

package com.example.friendster.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.friendster.fragment.ProfileFragment;

public class ProfileViewPagerAdapter extends FragmentPagerAdapter {
    int size =0;
    public ProfileViewPagerAdapter(FragmentManager fm,int size) {
        super(fm);
        this.size =size;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return new ProfileFragment();
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        return size;
    }
    @Nullable
    @Override
    public CharSequence getPageTitle (int positon)  {
        switch (positon){
            case 0:
                return "Posts";
                default:
                    return null;
        }

    }
}

profile_Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fafafa">


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@color/colorPrimary"
            app:expandedTitleGravity="bottom|right|start|center"
            app:expandedTitleMarginEnd="0dp"
            app:expandedTitleMarginStart="16dp"
            app:expandedTitleTextAppearance="@style/profileExpandedAppBar"
            app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                app:layout_collapseMode="parallax">


                <ImageView
                    android:id="@+id/profile_cover"
                    android:layout_width="match_parent"
                    android:layout_height="400dp"
                    android:minHeight="350dp"
                    android:paddingBottom="75dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/default_image_placeholder"
                    android:transitionName="shared"
                    app:layout_collapseMode="parallax" />


                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/profile_image"
                    android:layout_width="175dp"
                    android:layout_height="175dp"
                    android:layout_gravity="bottom|center"
                    android:elevation="2dp"
                    android:paddingBottom="10dp"
                    android:src="@drawable/img_default_user"
                    android:transitionName="shared"
                    app:civ_border_color="#000"
                    app:civ_border_width="1dp"
                    app:layout_collapseMode="parallax" />

                <Button
                    android:id="@+id/profile_option_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_gravity="bottom|end"
                    android:layout_marginBottom="20dp"
                    android:layout_marginEnd="10dp"
                    android:background="@drawable/background_button_round"
                    android:elevation="4dp"
                    android:gravity="center"
                    android:paddingEnd="5dp"
                    android:paddingStart="5dp"
                    android:text=""
                    android:textAllCaps="false"
                    app:layout_collapseMode="parallax" />


            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:title=""
                app:titleMarginStart="0dp"
                app:titleTextColor="#000" />

        </android.support.design.widget.CollapsingToolbarLayout>


    </android.support.design.widget.AppBarLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fafafa"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
            android:id="@+id/ViewPager_profile"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" >
            <!--   <android.support.v4.view.PagerTabStrip
                   android:id="@+id/pager_header"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_gravity="top"
                   android:paddingBottom="4dp"
                   android:paddingTop="4dp" />-->
        </android.support.v4.view.ViewPager>


    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

Android应用程序运行正常,但在运行方面向我显示了回收站视图:未连接适配器;跳过红色的布局将是一个问题

请帮助我。

0 个答案:

没有答案