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
136 views
in Technique[技术] by (71.8m points)

android - Cant see my CardView in fragment after clicked the spinner created

I want to make a compare laptop function by using spinner as the selection list and show it in CardView. I have created 2 Spinner and 2 Cardview put them into a fragment since I using bottom navigation for the whole system. After I try the solution available in StackOverflow doesn't fit me to solve the problem.

here my firebase

here the comparefragment.java`

public class CompareFragment extends Fragment {
  private Spinner spinner;
  private Spinner spinner2;
  private CardView card1, card2;
  ImageView imageView1 , imageView2;
  TextView  text1,text2,text3,text4,text5,text6,text7,text8,ted1,ted2,ted3,ted4,ted5,ted6,ted7,ted8;
  List<String> laptopname;
  private DatabaseReference mDatabaseReference;
  StorageReference StorageRef;
  FirebaseHelper helper;

  @Nullable
  @Override
  public View onCreateView(@Nullable LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle saveInstanceState) {
    View view = inflater.inflate(R.layout.fragment_compare2, container, false);
    spinner = (Spinner) view.findViewById(R.id.spinner);
    spinner2 = (Spinner) view.findViewById(R.id.spinner2);
    card1 = (CardView) view.findViewById(R.id.cv1);
    card2 = (CardView) view.findViewById(R.id.cv2);
    imageView1 = (ImageView)view.findViewById(R.id.imageView7);
    imageView2 = (ImageView)view.findViewById(R.id.imageView8);
    text1= (TextView)view.findViewById(R.id.laptopname);
    text2= (TextView)view.findViewById(R.id.price);
    text3= (TextView)view.findViewById(R.id.performance);
    text4= (TextView)view.findViewById(R.id.graphic);
    text5= (TextView)view.findViewById(R.id.design);
    text6= (TextView)view.findViewById(R.id.store);
    text7= (TextView)view.findViewById(R.id.ramu);
    text8= (TextView)view.findViewById(R.id.colo);
    ted1= (TextView)view.findViewById(R.id.laptopname2);
    ted2= (TextView)view.findViewById(R.id.price2);
    ted3= (TextView)view.findViewById(R.id.performance2);
    ted4= (TextView)view.findViewById(R.id.graphic2);
    ted5= (TextView)view.findViewById(R.id.design2);
    ted6= (TextView)view.findViewById(R.id.store2);
    ted7= (TextView)view.findViewById(R.id.ramu2);
    ted8= (TextView)view.findViewById(R.id.colo2);

    helper = new FirebaseHelper(mDatabaseReference);

    laptopname = new ArrayList<>();
    mDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mDatabaseReference.child("Laptop").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //ArrayList<String> lapname = new ArrayList<>();
            final List<String> lapname = new ArrayList<String>();
            lapname.add(0, "Choose a Laptop");

            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Laptop laptop = snapshot.getValue(Laptop.class);
                lapname.add(laptop.getLaptopName());
            }

            ArrayAdapter<String> nameAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, lapname);
            nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(nameAdapter);
            spinner2.setAdapter(nameAdapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selected = parent.getItemAtPosition(position).toString();
            Log.e("Clicked:",""+selected);
            if (position == 0) {
                Toast.makeText(getActivity(),"No Item Selected",Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getActivity(), parent.getItemAtPosition(position) + " Selected", Toast.LENGTH_SHORT).show();
                mDatabaseReference.child("Laptop").addValueEventListener(new ValueEventListener() {
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    String LaptopName = dataSnapshot.child("LaptopName").getValue(String.class);
                    String ImageUrl = dataSnapshot.child("ImageUrl").getValue(String.class);
                    String Price = dataSnapshot.child("Price").getValue(String.class);
                    String Performance = dataSnapshot.child("Performance").getValue(String.class);
                    String Graphic = dataSnapshot.child("Graphic").getValue(String.class);
                    String Design = dataSnapshot.child("Design").getValue(String.class);
                    String Storage = dataSnapshot.child("Storage").getValue(String.class);
                    String RAM = dataSnapshot.child("RAM").getValue(String.class);
                    String Color = dataSnapshot.child("Color").getValue(String.class);

                Picasso.get().load(ImageUrl).into(imageView1);
                text1.setText(LaptopName);
                text2.setText(Price);
                text3.setText(Performance);
                text4.setText(Graphic);
                text5.setText(Design);
                text6.setText(Storage);
                text7.setText(RAM);
                text8.setText(Color);
            }

                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {

                    }
                });
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
        }
    });
    spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selected = parent.getItemAtPosition(position).toString();
            Log.e("Clicked:", "" + selected);

            mDatabaseReference.child("Laptop").addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    String LaptopName = dataSnapshot.child("LaptopName").getValue(String.class);
                    String ImageUrl = dataSnapshot.child("ImageUrl").getValue(String.class);
                    String Price = dataSnapshot.child("Price").getValue(String.class);
                    String Performance = dataSnapshot.child("Performance").getValue(String.class);
                    String Graphic = dataSnapshot.child("Graphic").getValue(String.class);
                    String Design = dataSnapshot.child("Design").getValue(String.class);
                    String Storage = dataSnapshot.child("Storage").getValue(String.class);
                    String RAM = dataSnapshot.child("RAM").getValue(String.class);
                    String Color = dataSnapshot.child("Color").getValue(String.class);

                    Picasso.get().load(ImageUrl).into(imageView2);
                    ted1.setText(LaptopName);
                    ted2.setText(Price);
                    ted3.setText(Performance);
                    ted4.setText(Graphic);
                    ted5.setText(Design);
                    ted6.setText(Storage);
                    ted7.setText(RAM);
                    ted8.setText(Color);
                }

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

          @Override
          public void onNothingSelected(AdapterView<?> parent) {

          }
      });
      return(view);
  }

}

This what I get after run the system The app interface view

here the logcat

  2021-01-07 01:13:21.528 29844-29844/? I/ionadvisoryapp: Late-enabling -Xcheck:jni
2021-01-07 01:13:21.565 29844-29844/? E/ionadvisoryapp: Unknown bits set in runtime_flags: 0x8000
2021-01-07 01:13:21.566 29844-29844/? I/ionadvisoryapp: Reinit property: dalvik.vm.checkjni= false
2021-01-07 01:13:21.584 29844-29844/? W/re-initialized>: type=1400 audit(0.0:10072467): avc: denied { read } for pid=29844 name="u:object_r:mmi_prop:s0" dev="tmpfs" ino=4562 scontext=u:r:untrusted_app:s0:c48,c257,c512,c768 tcontext=u:object_r:mmi_prop:s0 tclass=file permissive=0
2021-01-07 01:13:21.587 29844-29844/? E/libc: Access denied finding property "runtime.mmitest.isrunning"
2021-01-07 01:13:21.592 29844-29844/? D/ActivityThread: Attach thread to application
2021-01-07 01:13:22.287 29844-29865/com.example.laptopselectionadvisoryapps I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.laptopselectionadvisoryapps#10304#256
2021-01-07 01:13:22.288 29844-29844/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::Init
2021-01-07 01:13:22.288 29844-29844/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::StartWatch
2021-01-07 01:13:22.288 29844-29865/com.example.laptopselectionadvisoryapps I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.laptopselectionadvisoryapps#10304#0
2021-01-07 01:13:22.288 29844-29844/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
2021-01-07 01:13:22.288 29844-29844/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/com.example.laptopselectionadvisoryapps
2021-01-07 01:13:22.288 29844-29844/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
2021-01-07 01:13:22.288 29844-29844/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::Run
2021-01-07 01:13:22.289 29844-29881/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::Reading
2021-01-07 01:13:22.289 29844-29881/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::CheckNotifyEvent
2021-01-07 01:13:22.289 29844-29881/com.example.laptopselectionadvisoryapps I/ionadvisoryapp: QarthPatchMonintor::CheckNotifyEvent before read
2021-01-07 01:13:22.293 29844-29865/com.example.laptopselectionadvisoryapps I/AwareBitmapCacher: init processName:com.example.laptopselectionadvisoryapps pid=29844 uid=10304
2021-01-07 01:13:22.309 29844-29844/com.example.laptopselectionadvisoryapps W/ComponentDiscovery: Class com.google.firebase.dynamicloading.DynamicLoadingRegistrar is not an found.
2021-01-07 01:13:22.309 29844-29883/com.example.laptopselectionadvisoryapps E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@17b9361
2021-01-07 01:13:22.319 29844-29844/com.example.laptopselectionadvisoryapps I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2021-01-07 01:13:22.354 29844-29844/com.example.laptopselectionadvisoryapps I/FirebaseInitProvider: FirebaseApp initialization successful
2021-01-07 01:13:22.366 29844-29889/com.example.laptopselectionadvisoryapps I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connec

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

...