第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

列表視圖僅顯示數(shù)組列表的第一個(gè)結(jié)果

列表視圖僅顯示數(shù)組列表的第一個(gè)結(jié)果

函數(shù)式編程 2023-06-08 17:40:31
我有下面的代碼顯示數(shù)組列表的結(jié)果,但是,它只顯示測試結(jié)果,我將相同的結(jié)果附加到文本視圖進(jìn)行測試,發(fā)現(xiàn)我從查詢方法得到的結(jié)果確實(shí)包含多個(gè)他們出現(xiàn)在文本視圖中,但列表視圖只顯示第一個(gè)。請?jiān)谙旅嬲业酱a以及所附圖片。<?xml version="1.0" encoding="utf-8"?><androidx.coordinatorlayout.widget.CoordinatorLayout 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=".search.searchActivity">    <EditText        android:id="@+id/userInputtxt2"        android:layout_width="match_parent"        android:layout_height="30dp"        android:layout_marginStart="8dp"        android:paddingTop="50dp"        android:textColor="@color/Black"        android:textSize="18sp" />    <EditText        android:id="@+id/userInputtxt"        android:layout_width="match_parent"        android:layout_height="30dp"        android:layout_marginStart="8dp"        android:paddingTop="50dp"        android:textColor="@color/Black"        android:textSize="18sp" />    <Button        android:id="@+id/findBtn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginStart="320dp"        android:layout_marginEnd="3dp"        android:text="find"        android:textSize="10sp" />    <ListView        android:id="@+id/listview4"        android:layout_width="398dp"        android:layout_height="wrap_content"        android:layout_marginStart="8dp"        android:layout_marginTop="55dp"        android:layout_marginEnd="8dp"        android:layout_marginBottom="8dp">    </ListView>    <TextView        android:id="@+id/resultTxt"        android:layout_width="match_parent"        android:layout_height="203dp"        android:layout_marginTop="450dp"        android:background="@color/transparentGrey"        android:text="TextView" /></androidx.coordinatorlayout.widget.CoordinatorLayout>
查看完整描述

2 回答

?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊

if (match != null) {

    ArrayList<String> namesList = new ArrayList<>();

    resultTxt.setText( matcheddata );

    // namesList.clear(); // You don't need to clear it as you just created it above

    namesList.add(matcheddata);

    ArrayAdapter<String> adapter = new ArrayAdapter<>( getApplicationContext(), android.R.layout.simple_selectable_list_item, namesList );

    listView.setAdapter(adapter);

}

嗨 Amer Anajjem,您可以嘗試在創(chuàng)建適配器之前準(zhǔn)備 namesList 并使用最新的 namesList 來創(chuàng)建適配器。


編輯:


我發(fā)現(xiàn)問題是:matcheddata是一個(gè)字符串。當(dāng)您致電時(shí)namesList.add(matcheddata);,您僅將 1 項(xiàng)添加到列表中。結(jié)果,您在列表視圖中只有 1 個(gè)項(xiàng)目。為了證明這一點(diǎn),您可以嘗試以下操作:


if (match != null) {

    ArrayList<String> namesList = new ArrayList<>();

    resultTxt.setText( matcheddata );

    namesList.clear();

    namesList.add(matcheddata);

    namesList.add(matcheddata);

    ArrayAdapter<String> adapter = new ArrayAdapter<>( getApplicationContext(), android.R.layout.simple_selectable_list_item, namesList );

    listView.setAdapter(adapter);

}

您應(yīng)該在列表視圖中看到 2 個(gè)重復(fù)的項(xiàng)目。


編輯 2:


你可以試試這個(gè),但我沒有測試過。


package com.example.boc.search;


import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;


import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.LinearLayout;

import android.widget.ListView;

import android.widget.TextView;


import com.example.boc.Interface.IMainActivity;

import com.example.boc.R;

import com.example.boc.main.phone_nombers_Activity;

import com.example.boc.models.Note;

import com.example.boc.models.Search;

import com.google.android.gms.tasks.OnCompleteListener;


import android.widget.ArrayAdapter;


import com.google.android.gms.tasks.Task;

import com.google.firebase.firestore.CollectionReference;

import com.google.firebase.firestore.DocumentReference;

import com.google.firebase.firestore.DocumentSnapshot;

import com.google.firebase.firestore.FirebaseFirestore;

import com.google.firebase.firestore.Query;

import com.google.firebase.firestore.QueryDocumentSnapshot;

import com.google.firebase.firestore.QuerySnapshot;


import java.util.ArrayList;


public class searchActivity extends phone_nombers_Activity implements

        View.OnClickListener,

        IMainActivity

{


    private DocumentSnapshot documentSnapshot;

    ListView listView;

    public TextView resultTxt , userinput ;

    private ArrayList<Search> mSearch = new ArrayList<>();



    public FirebaseFirestore db = FirebaseFirestore.getInstance();

    public Note note ;

    public LinearLayout layout ;


    private ArrayList<Note> mNotes = new ArrayList<>();


    private DocumentReference noteRef = db.collection("notes").document();

    private CollectionReference notesCollectionRef = db.collection("notes");

    private RecyclerView mRecyclerView;



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate( savedInstanceState );

        setContentView( R.layout.activity_search );

        final ListView listView = findViewById( R.id.listview4 );

        final EditText userinput = findViewById( R.id.userInputtxt );

        final Button   findbutton = findViewById( R.id.findBtn );

        final TextView resultTxt = findViewById( R.id.resultTxt );

        mRecyclerView = findViewById(R.id.recycler_view);


        FirebaseFirestore db = FirebaseFirestore.getInstance();


        CollectionReference notesCollectionRef = db

                .collection("notes");


        Query notesQuery = null;

        if(documentSnapshot != null){

            notesQuery = notesCollectionRef;


        }

        else{

            notesQuery = notesCollectionRef

                    .orderBy("timestamp", Query.Direction.ASCENDING);

        }



        notesQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

            @Override

            public void onComplete(@NonNull Task<QuerySnapshot> task) {

                if(task.isSuccessful()){

                    String data = "";


                    for(final QueryDocumentSnapshot document: task.getResult()){

                        Note note = document.toObject(Note.class);


                        mNotes.add(note);

                        if( userinput !=null ) {

                            findbutton.setOnClickListener( new View.OnClickListener() {

                                @Override

                                public void onClick(View v) {

                                    final String userinputString = userinput.getText().toString();


                                    ArrayList<String> namesList = new ArrayList<>();

                                    for (Note note : mNotes) {

                                        if (note.getTitle().contains(userinputString)) {

                                            String matchedtitle = note.getTitle();

                                            String matchedcontent = note.getContent();

                                            String matcheddata += "????:" + matchedcontent + "\n?????:" + matchedtitle + "\n\n";

                                            namesList.add(matcheddata);

                                    }


                                    ArrayAdapter<String> adapter = new ArrayAdapter<>( getApplicationContext(), android.R.layout.simple_selectable_list_item, namesList );

                                    listView.setAdapter(adapter);

                                }


                            } );

                        }

                        else {

                            userinput.setError( "??? ????? ?????" );

                        }

                    }

                }

            }

        });

    }


    @Override

    public void onStart () {


        super.onStart();


    }

}



查看完整回答
反對 回復(fù) 2023-06-08
?
揚(yáng)帆大魚

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊

我認(rèn)為這是適配器通知問題。

  • 您正在向適配器提供 0 大小列表,并立即通知適配器。

  • 我認(rèn)為您應(yīng)該在添加到列表后通知適配器。或者您可以在調(diào)用適配器類之前將數(shù)據(jù)添加到列表中。

例子

notesQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override

        public void onComplete(@NonNull Task<QuerySnapshot> task) {

            if(task.isSuccessful()){

                String data = "";


                for(final QueryDocumentSnapshot document: task.getResult()){

                    Note note = document.toObject(Note.class);


                    mNotes.add(note);

                    if( userinput !=null ) {

                        findbutton.setOnClickListener( new View.OnClickListener() {

                            @Override

                            public void onClick(View v) {

                                final String userinputString = userinput.getText().toString();


                                Note match = null;

                                String matcheddata ="";

                                for (Note note : mNotes) {

                                    if (note.getTitle().contains(userinputString)) {

                                        match = note;

                                        String matchedtitle = match.getTitle();

                                        String matchedcontent = match.getContent();

                                        matcheddata += "????:" + matchedcontent + "\n?????:" + matchedtitle + "\n\n";

                                    }

                                }

                                if (match != null) {

                                    ArrayList<String> namesList = new ArrayList<>();

                                    resultTxt.setText( matcheddata );

                                    namesList.clear();

                                    namesList.add(matcheddata);

                                    ArrayAdapter<String>adapter = new ArrayAdapter<>( getApplicationContext(), android.R.layout.simple_selectable_list_item, namesList );

                                    listView.setAdapter(adapter);

                                }

                            }

                        } );

                    }

                    else {

                        userinput.setError( "??? ????? ?????" );

                    }

                }

            }

        }

    });

只需更改上面的功能并嘗試。


查看完整回答
反對 回復(fù) 2023-06-08
  • 2 回答
  • 0 關(guān)注
  • 176 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)