Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

android - set Height of View Holder in OnBindViewHolder of Firebase Recycler

I have a recyclerview in which I want to check for a condition first and then show the item in the recycler view. So I tried setting the View.visibility(gone) but it is leaving blank spaces and the values are coming out fine. But then I tried setting up the params for height in view which is turned out to be a disaster and now nothing is coming up on my screen. below is what i have done

In my onCreateView I call a fragment Place Autocomplete

      autocompleteFragment.setOnPlaceSelectedListener
      (new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
           
            myPosition = null;
            Toast.makeText(getContext(),place.getAddress(),
             Toast.LENGTH_LONG).show();
          

            Double latitude1 = place.getLatLng().latitude;
            Double longitude1 =place.getLatLng().longitude;
            LatLng latLng = new LatLng(latitude1,longitude1);
            myPosition = latLng;
           
            filterResults(myPosition); //this i s for geoquery



        }

 private Map<String, GeoLocation> UIDLocation = new HashMap<>();
 public void filterResults(LatLng latLng){


    DatabaseReference ref = 
    FirebaseDatabase.getInstance().getReference().child("Location");
    GeoFire geoFire = new GeoFire(ref);
    GeoQuery geoQuery = geoFire.queryAtLocation(new 
    GeoLocation(latLng.latitude, latLng.longitude), 2);
    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            UIDLocation.put(key,location);
        }
       // further methods of geoquery event listenere i havent changed 
      anything in them -----
     ------ public void onGeoQueryError(DatabaseError error) {
        }
    });
   filterlocation();  // this method call the firebase adapter 
    }


    public static class UsersViewHolder extends RecyclerView.ViewHolder {
    View mView;
    public UsersViewHolder(View itemView) {
        super(itemView);
        mView = itemView;
    }
    public void show(){
        mView.setVisibility(View.VISIBLE);
        mView.setLayoutParams(new 
    ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
    ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    public void hide(){
        mView.setVisibility(View.GONE);
        mView.setLayoutParams(new ViewGroup.LayoutParams(0,0));
    }
    /*
    public void setLayoutParams(ViewGroup.LayoutParams layoutParams)
    {
      mView.setLayoutParams(layoutParams);
    }
    */
    TextView userNameView;
    public void setDisplayName(String name)
    {
        userNameView = (TextView) mView.findViewById(R.id.search_name);
        userNameView.setText(name);
    }
    TextView userCategory;
    public void setUserCategory(String name)
    {
        userCategory = (TextView) mView.findViewById(R.id.search_category);
        userCategory.setText(name);
    }
    TextView userLocation;
    public void setUserLocation(String name)
    {
        userLocation = (TextView) mView.findViewById(R.id.search_location);
        userLocation.setText(name);
    }
    TextView userStatusView;
    public void setUserStatus(String status)
    {
         userStatusView = (TextView) 
         mView.findViewById(R.id.search_category);
         userStatusView.setText(status);
    }
    public void setTypeFace(Typeface t){
        userNameView.setTypeface(t);
    }
 }

my OnBinViewHolder method is

         protected void onBindViewHolder(final UsersViewHolder holder, int 
         position, final Users model) {
            GeoLocation g = UIDLocation.get(model.getLocationID());
               if (g != null)
            {
                holder.show();
              holder.setLayoutParams();

                Toast.makeText(getContext(), "added", 
                Toast.LENGTH_SHORT).show();
                Log.d("added", "onBindViewHolder: ");
            }
            else{
                holder.hide();

                Toast.makeText(getContext(), "not Addded", 
                Toast.LENGTH_SHORT).show();
                Log.d("not added", "onBindViewHolder: ");

                holder.setLayoutParamszero();
            }

            holder.setDisplayName(model.getName());
            String image = model.getThumb_image();
            holder.setUserImage(image, getContext());
            holder.setTypeFace(typeface);
            holder.setUserCategory(model.getSubcategory());
            holder.setUserLocation(model.getLocation());


            holder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
               Toast.makeText(getContext(), model.getName(), 
               Toast.LENGTH_SHORT).show();
                }
            });

        }

my layout file

 <?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"
  android:id="@+id/search_result_layout"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="?android:selectableItemBackground">
          <TextView
                android:id="@+id/search_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/search_name"
                android:layout_below="@+id/user_single_online_icon"

                android:layout_marginBottom="3dp"
                android:layout_marginTop="3dp"
                android:text="Location" />

            <ImageView
                android:id="@+id/user_single_online_icon"
                android:layout_width="8dp"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/search_name"
                android:layout_marginLeft="10dp"
                android:layout_toEndOf="@+id/search_name"
                android:visibility="invisible"
                app:srcCompat="@drawable/online_icon" />

            <ImageView
                android:id="@+id/search_user_single_image"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:layout_marginBottom="15dp"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="15dp"
                android:src="@drawable/default_avatar" />

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/nextbtn1"

                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_navigate_next_black_24dp" />

            <TextView
                android:id="@+id/search_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/search_user_single_image"
                android:layout_marginStart="20dp"
                android:layout_toEndOf="@+id/search_user_single_image"
                android:text="Display Name"
                android:textColor="@android:color/black"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/search_category"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/search_name"
                android:layout_below="@+id/search_name"
                android:layout_marginBottom="3dp"
                android:layout_marginTop="3dp"
                android:text="Category" />



 </RelativeLayout>

 

view.hide() is working fine without the params and showing values but the values are totally gone in every condition when I apply the params on View

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...