简体   繁体   中英

How to displayed information on pop up window from the card view

I am developing an app similar to tinder but this is not dating app.

I am working on the card view function and have encountered some errors I am unable to solve.

Here is the card view function of the app I have successfully coded (for the time being).

The Main layout (top portion of card) contains the profile image and user name. The second is pop up window contains text fields.

Users will see details of other users on the card view.

I have the option to view more information about another user by touching a more information button. When the more information button is selected, pop up window will be animated

The user can go back to the default view, by touching the icon to reduce the 'more information' display.

At the moment, I am facing an issue with the information displayed on pop up window of the card view after a swipe has been performed. The issue is that the text fields in the pop up window need to seamlessly update when a card swipe has been performed and a new user's card has been displayed.

user information is via firebase real time database

Card view


<android.support.constraint.ConstraintLayout 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:id="@+id/constraint2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@android:color/white"
    android:clipToPadding="false"
    android:outlineProvider="bounds"
    android:paddingLeft="1sp"
    android:paddingTop="1sp"
    android:paddingRight="1sp"
    android:paddingBottom="1sp">

  <android.support.v7.widget.CardView
      android:id="@+id/cw1"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_gravity="center"
      android:elevation="0dp"
      app:cardCornerRadius="2dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="0.54"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent">


    <android.support.constraint.ConstraintLayout

        android:id="@+id/job12"
        android:layout_width="match_parent"

        android:layout_height="match_parent"
        android:animateLayoutChanges="false"
        android:background="@android:color/black"
        android:clickable="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.498">

      <ImageView
          android:id="@+id/imgRandomxx"
          android:layout_width="137dp"
          android:layout_height="2dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:layout_weight="1"
          android:background="@android:color/black"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.502"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.0" />

      <ImageView
          android:id="@+id/imagexx"
          android:layout_width="0dp"
          android:layout_height="641dp"
          android:layout_marginStart="1dp"
          android:layout_marginEnd="1dp"
          android:layout_marginBottom="8dp"
          android:background="@android:color/black"
          android:scaleType="centerCrop"

          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.0" />

      <TextView
          android:id="@+id/textView2zz"
          android:layout_width="28dp"
          android:layout_height="23dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:background="@drawable/common_google_signin_btn_icon_dark"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.93"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.13999999" />

      <View
          android:id="@+id/item2_swipe_right_indicator"
          android:layout_width="133dp"
          android:layout_height="133dp"
          android:layout_gravity="right"
          android:layout_marginStart="8dp"


          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:alpha="0"
          android:background="@drawable/sswwepleft"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="1.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.312" />

      <View
          android:id="@+id/item2_swipe_left_indicator"
          android:layout_width="127dp"
          android:layout_height="140dp"
          android:layout_marginStart="8dp"

          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:alpha="0"
          android:background="@drawable/swweeprright"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.007"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.316" />

      <TextView
          android:id="@+id/namexx"
          android:layout_width="136dp"
          android:layout_height="35dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:background="@android:color/transparent"
          android:gravity="start"
          android:paddingLeft="20sp"
          android:textAllCaps="true"
          android:textColor="@android:color/white"
          android:textSize="30sp"
          app:fontFamily="@font/calibril"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.006"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.85"
          tools:text="hello" />

      <TextView
          android:id="@+id/textViewdditanssjob"
          android:layout_width="39dp"
          android:layout_height="29dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:fontFamily="@font/calibril"
          android:maxLength="4"
          android:maxLines="1"
          android:textColor="@android:color/white"
          android:textSize="18sp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.018"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.939" />

      <TextView
          android:id="@+id/textView15"
          android:layout_width="104dp"
          android:layout_height="37dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:fontFamily="@font/calibril"

          android:text="km away"
          android:textColor="@android:color/white"
          android:textSize="18sp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.116"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.95" />

      <TextView
          android:id="@+id/scoretestViewxx"
          android:layout_width="106dp"
          android:layout_height="45dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:gravity="center"
          android:text="0"
          android:textAllCaps="true"
          android:textColor="@android:color/white"
          android:textSize="35sp"
          android:textStyle="bold"
          app:fontFamily="@font/wcmanonegrabta"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"

          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.042" />

      <TextView
          android:id="@+id/textViewxxyy"
          android:layout_width="209dp"
          android:layout_height="30dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:gravity="center"
          android:text="about me"
          android:textColor="@android:color/black"
          android:textSize="19sp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.442"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="1.0" />

      <Button
          android:id="@+id/button4infoor"
          android:layout_width="45dp"
          android:layout_height="45dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:background="@drawable/infoicon"
          android:clickable="false"
          android:onClick="animateViewFromBottomToTop"
          android:stateListAnimator="@null"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.968"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.87" />


    </android.support.constraint.ConstraintLayout>


  </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

pop up window



 public  void animateViewFromBottomToTop( View view){



        // inflate the layout of the popup window
        LayoutInflater inflater2 = (LayoutInflater)
                getSystemService(LAYOUT_INFLATER_SERVICE);

        View popupView2 = inflater2.inflate(R.layout.popup_windowjj, null);


        Button btn= (Button) popupView2.findViewById(R.id.button4infoor3j);



        // create the popup window
        // int width = LinearLayout.LayoutParams.WRAP_CONTENT;
        /// int height = LinearLayout.LayoutParams.WRAP_CONTENT;
        int width = LinearLayout.LayoutParams.MATCH_PARENT;
        int height = (int)(getResources().getDisplayMetrics().heightPixels*0.50);

        boolean focusable = false; // lets taps outside the popup also dismiss it
        final PopupWindow popupWindow2 = new PopupWindow(popupView2, width, height, focusable);
        popupWindow2.setFocusable(false);
        popupWindow2.setOutsideTouchable(false);

        final String yourString = userName;

        final TextView popupText = (TextView) popupView2.findViewById(R.id.textView13j);

        popupText.setText(yourString);

        // show the popup window
        // which view you pass in doesn't matter, it is only used for the window tolken

        popupWindow2.setAnimationStyle(R.style.styleAnimationResourceCardviewpopup);
        popupWindow2.showAtLocation(popupView2, Gravity.BOTTOM, 0, 0);

        // dismiss the popup window when touched
        btn.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {


                popupWindow2.dismiss();
                return true;

            }
        });


    }

I am looking for advice to have the user profile data to be seamlessly updated on pop up window.

value is stored in 'userName' variable from below code

flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {
                @Override
                public void onItemClicked(int itemPosition, Object dataObject) {



                cardsxx obj = (cardsxx) dataObject;
                String userId = obj.getUserId();


                DatabaseReference userDb3 = usersDb4.child(obj.getUserId());


                userDb3.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        if (dataSnapshot.exists()){
                            if (dataSnapshot.child("email").getValue() != null){
                                useremail = dataSnapshot.child("email").getValue().toString();
                                userName=dataSnapshot.child("name").getValue().toString();
                                userJob = dataSnapshot.child("industry").getValue().toString();

                            }
                        }
                    }
                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });




            }
        });
``````````````````````````````````````````````````````

The problem here is, you are not able to pass latest 'userName' value when you click over 'more information button'.

One of the solution for this is : I assume you are using recyclerview/listview to show other users information. If you are using recycler-view, then you also must be having an adapter of it and a viewHolder of it. Adapter has a function 'onBindViewHolder', which will parser every view and data object, and you need to assign data to view in this method. Now you should implement 'setOnClickListener' of 'button4infoor' in this method and remove it from view of .xml. So below mentioned logic should go inside 'onClick()' method

DatabaseReference userDb3 = usersDb4.child(obj.getUserId());


            userDb3.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.exists()){
                        if (dataSnapshot.child("email").getValue() != null){
                            useremail = dataSnapshot.child("email").getValue().toString();
                            userName=dataSnapshot.child("name").getValue().toString();
                            userJob = dataSnapshot.child("industry").getValue().toString();
                            animateViewFromBottomToTop(useremail, userName, userJob);
                        }
                    }
                }
                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

And pass user related values to function 'animateViewFromBottomToTop' and set views accordingly. But all this will work if you are using recyclerview/listview. Let me know if you have any other query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM