在Firebase Recycler的OnBindViewHolder中设置View Holft的高度

时间:2018-05-29 20:12:26

标签: android firebase view android-recyclerview recycler-adapter

我有一个回收站视图,我想首先检查一个条件,然后在回收站视图中显示该项目。所以我尝试设置VIew.visibility(已消失),但它留下了空格,值很好。但后来我尝试在视野中设置高度的参数,这被证明是一场灾难,现在我的屏幕上什么都没有出现。 以下是我所做的事情

在我的onCreateView中我调用片段放置自动完成

      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);
    }
 }

我的OnBinViewHolder方法是

         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();
                }
            });

        }

我的布局文件

 <?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工作正常没有参数并显示值但是当我在视图上应用参数时,值在每种情况下都完全消失了

0 个答案:

没有答案