Firebase适配器不显示用户信息

时间:2019-02-18 15:02:10

标签: android firebase firebase-realtime-database recycler-adapter

我正在尝试在我的应用程序上显示搜索到的信息,但是当我单击搜索按钮而不是显示用户信息时,什么都不会显示

我不知道为什么我没有显示我尝试了不同的方法,现在仍然显示用户。……

请帮助!谢谢..

查找朋友活动:

public class findfriendsActivity extends AppCompatActivity {
    private Toolbar mToolbar;
    private EditText userinputsearch;
    private ImageButton searchbuttonclicked;
    private RecyclerView searchedrsultprofiles;
    private DatabaseReference searchref;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_findfriends);

        mToolbar=findViewById(R.id.findfrineds_app_bar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Update Post");

        searchref = FirebaseDatabase.getInstance().getReference();

        searchedrsultprofiles = findViewById(R.id.result_list);
        searchedrsultprofiles.setHasFixedSize(true);
        searchedrsultprofiles.setLayoutManager(new LinearLayoutManager( this));

        searchbuttonclicked=findViewById(R.id.searchedbutton);
        userinputsearch = findViewById(R.id.search_here_for_friends);

        searchbuttonclicked.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String searchedperson = userinputsearch.getText().toString();
                Toast.makeText(findfriendsActivity.this,"searching",Toast.LENGTH_SHORT).show();

                searchforfriend(searchedperson);
            }
        });
    }

    private void searchforfriend(String searchedperson) {

        Query query = FirebaseDatabase.getInstance().getReference("username/profileimage/status");

        FirebaseRecyclerOptions<Findfrnd> options=
                new FirebaseRecyclerOptions.Builder<Findfrnd>()
                        .setQuery(query,Findfrnd.class)
                        .build();

        FirebaseRecyclerAdapter<Findfrnd,findfreindsviewholder> firebaseRecyclerAdapter
                =new FirebaseRecyclerAdapter<Findfrnd, findfreindsviewholder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull findfreindsviewholder findfreindsviewholder, int position, @NonNull Findfrnd findfrnd) {
                findfreindsviewholder.username2.setText(findfrnd.getUsername());
                findfreindsviewholder.status.setText(findfrnd.getStatus());
                Picasso.get().load(findfrnd.getProfileimage()).into(findfreindsviewholder.searchedprofileimage);

            }

            @NonNull
            @Override
            public findfreindsviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.all_userssearched,parent, false);
                findfreindsviewholder viewholder = new findfreindsviewholder(view);
                return viewholder;

            }
        };
    }


    public static class findfreindsviewholder extends RecyclerView.ViewHolder{

        TextView username2,status;
        CircleImageView searchedprofileimage;

       View mView;

        public findfreindsviewholder(@NonNull View itemView) {
            super(itemView);
            mView = itemView;

            username2 =itemView.findViewById(R.id.all_users_searched_username);
            status = itemView.findViewById(R.id.all_users_searched_status);
            searchedprofileimage= itemView.findViewById(R.id.searcheduserprofileimage);
        }
    }
}


Findfrnd:

软件包aj_studio.bfit;

公共类Findfrnd {

public String profileimage,status,username;

public Findfrnd(){

}

public Findfrnd(String profileimage, String status, String username) {
    this.profileimage = profileimage;
    this.status = status;
    this.username = username;
}

public String getProfileimage() {
    return profileimage;
}

public void setProfileimage(String profileimage) {
    this.profileimage = profileimage;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

}

查找朋友活动:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".findfriendsActivity"
    android:background="@color/colorprofile">

    <include
        android:id="@+id/findfrineds_app_bar"
        layout="@layout/app_bar">
    </include>

    <RelativeLayout
        android:id="@+id/searchfirst_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:layout_below="@+id/findfrineds_app_bar"
        android:layout_marginTop="1dp">


        <TextView
            android:id="@+id/search_info"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="search for  friends from local gym, gym mentors etc.... "
            android:textColor="@color/common_google_signin_btn_text_dark_default"
            android:ems="10"
            android:layout_marginStart="20dp"
            android:layout_marginLeft="20dp"
            android:textSize="18dp"/>

        <EditText
            android:id="@+id/search_here_for_friends"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/search_info"
            android:hint="search here ..."
            android:textColorHint="@color/colorprofile"
            android:textColor="@color/colorprofile"
            android:ems="10"
            android:layout_marginTop="10dp"
            android:padding="5dp"
            android:textSize="17dp"
            android:layout_marginEnd="60dp"
            android:layout_marginStart="20dp"
            android:layout_marginLeft="20dp"
            android:inputType="textMultiLine"
            android:background="@drawable/input"
            android:layout_marginRight="60dp" />

        <ImageButton
            android:id="@+id/searchedbutton"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_below="@id/search_info"
            android:layout_marginStart="290dp"
            android:scaleType="centerCrop"

            android:layout_marginLeft="302dp"
            android:layout_marginTop="3dp"
            android:background="@drawable/input"
            android:src="@drawable/search" />
    </RelativeLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/result_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/searchfirst_layout"
        android:layout_marginTop="1dp"
        android:layout_alignParentLeft="true"
        android:layout_margin="10dp">

    </androidx.recyclerview.widget.RecyclerView>


</RelativeLayout>

usersserched activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorprofile"
    android:layout_margin="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"

        >

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/searcheduserprofileimage"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_marginLeft="10dp"
            android:src="@drawable/profile"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_margin="5dp">

            <TextView
                android:id="@+id/all_users_searched_username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@android:color/background_light"
                android:text="User Full Name"
                android:textAlignment="textStart"
                android:textSize="17dp"
                android:gravity="start" />
            <TextView
                android:id="@+id/all_users_searched_status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAlignment="textStart"
                android:textColor="@android:color/background_light"
                android:text="User Status"
                android:textSize="15dp"
                android:gravity="start" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

0 个答案:

没有答案