简体   繁体   English

如何隐藏某些内容以不显示给 recyclerview

[英]How can I hide some content from showing to recyclerview

I am working on code which I copied from somewhere as a learner.我正在研究我作为学习者从某个地方复制的代码。 The app displays data in recyclerview, this data is coming from firebase database.该应用程序在recyclerview中显示数据,该数据来自firebase数据库。 All is working well, the data is displaying nicely in recyclerview.一切运行良好,数据在 recyclerview 中显示得很好。

My worry now is: i have added another recyclerview in the same activity.我现在担心的是:我在同一个活动中添加了另一个 recyclerview。 So now I have two recyclerviews with these IDs: recyclerview and recyclerview2.所以现在我有两个具有这些 ID 的 recyclerview:recyclerview 和 recyclerview2。 They are in one activity but in different layouts, and only one layout is visible at a time, and by clicking the button it hides one layout and shows another.它们在一个活动中,但在不同的布局中,一次只能看到一个布局,通过单击按钮,它会隐藏一个布局并显示另一个布局。 For now the recyclerviews are showing same data.目前,recyclerviews 显示相同的数据。

What i want now is this: In these recyclerviews I have a TextView which changes text time by time.我现在想要的是:在这些 recyclerviews 中,我有一个 TextView,它会随时间改变文本。 It sometimes shows this text 'CLOSED'.它有时会显示此文本“已关闭”。 So i want all the data which has a textview which shows 'CLOSED' to be shown on recyclerview2 and will be unavailable on the first recyclerview.所以我希望所有具有 textview 的数据都显示在 recyclerview2 上,并且在第一个 recyclerview 上不可用。

So my issue is to make the data not to display on recyclerview (first one) if the textview is showing 'CLOSED' and i want the recyclerview2 to show only data which has a textview showing this text 'CLOSED'所以我的问题是如果 textview 显示“已关闭”并且我希望 recyclerview2 仅显示具有 textview 显示此文本“已关闭”的数据,则使数据不显示在 recyclerview(第一个)上

I do not know where to start from.我不知道从哪里开始。 Below is my MainActivity.java where i want the code to be added.下面是我想要添加代码的 MainActivity.java。

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView, recyclerView2;
    private DatabaseReference mDatabase, vDatabase;
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;


    TextView rtrratio, rtrratiopercentage, tppipss, slpipss, commenting, entry, tp, sl, tv1, tv2, tv3;
    RelativeLayout rSignals, rCalendar, rLessons, rServices, rContact;
    ImageButton imsignals, imcalendar, imlessons, imservices, imcontact;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);

        //defining main buttons (Image buttons)
        imsignals = (ImageButton) findViewById(R.id.im_signals_id);
        imcalendar = (ImageButton) findViewById(R.id.im_calendar_id);
        imlessons = (ImageButton) findViewById(R.id.im_lessons_id);
        imservices = (ImageButton) findViewById(R.id.im_services_id);
        imcontact = (ImageButton) findViewById(R.id.im_contact_id);


        //defining textviews
        entry = (TextView) findViewById(R.id.entry);
        tppipss = (TextView) findViewById(R.id.tpp);
        slpipss = (TextView) findViewById(R.id.slp);
        rtrratio = (TextView) findViewById(R.id.riskreward);
        rtrratiopercentage = (TextView) findViewById(R.id.rrewardp);
        commenting = (TextView) findViewById(R.id.comment);
        tp = (TextView) findViewById(R.id.tp);
        sl = (TextView) findViewById(R.id.sl);


        //bottom navigation
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        //button definitions
        Button btnRunning = (Button) findViewById(R.id.sRunning);
        Button btnPending = (Button) findViewById(R.id.sPending);
        Button btnClosed = (Button) findViewById(R.id.sClosed);

        //layouts definitions for bottom navigation
        rSignals = (RelativeLayout) findViewById(R.id.rlsignals);
        rCalendar = (RelativeLayout) findViewById(R.id.rlcalendar);
        rLessons = (RelativeLayout) findViewById(R.id.rllessons);
        rServices = (RelativeLayout) findViewById(R.id.rlservices);
        rContact = (RelativeLayout) findViewById(R.id.rlcontact);

        //layouts definitions for signals layout
        final RelativeLayout rRunning = (RelativeLayout) findViewById(R.id.rlRunning);
        final LinearLayout rPending = (LinearLayout) findViewById(R.id.rlHistory);
        final LinearLayout rClosed = (LinearLayout) findViewById(R.id.rlRating);


        //initialize recyclerview and FIrebase objects
        //for running signals
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setHasFixedSize(true);
        //for closed signals
        recyclerView2 = (RecyclerView) findViewById(R.id.recyclerview2);
        recyclerView2.setLayoutManager(new LinearLayoutManager(this));
        recyclerView2.setHasFixedSize(true);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setReverseLayout(true);
        linearLayoutManager.setStackFromEnd(true);
        //for running signals
        recyclerView.setLayoutManager(linearLayoutManager);
        //for closed signals
        recyclerView.setLayoutManager(linearLayoutManager);

        //for signals get child as Blogzone
        mDatabase = FirebaseDatabase.getInstance().getReference().child("Blogzone");
        mAuth = FirebaseAuth.getInstance();
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                if (mAuth.getCurrentUser() == null) {
                    Intent loginIntent = new Intent(MainActivity.this, RegisterActivity.class);
                    loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(loginIntent);
                }
            }
        };


    /////////////////////////////////////////////////////////////////////////////////////////////
    //signals
    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
        FirebaseRecyclerAdapter<Blogzone, BlogzoneViewHolder> FBRA = new FirebaseRecyclerAdapter<Blogzone, BlogzoneViewHolder>(
                Blogzone.class,
                R.layout.card_items,
                BlogzoneViewHolder.class,
                mDatabase

        ) {
            @Override
            protected void populateViewHolder(BlogzoneViewHolder viewHolder, Blogzone model, int position) {
                final String post_key = getRef(position).getKey().toString();
                viewHolder.setPair(model.getPair());
                viewHolder.setBuySell(model.getBuysell());
                viewHolder.setOpenPrice(model.getOpenprice());
                viewHolder.setTakeProfit(model.getTakeprofit());
                viewHolder.setStopLoss(model.getStoploss());
                viewHolder.setProfitPips(model.getProfitpips());
                viewHolder.setLossPips(model.getLosspips());
                viewHolder.setComment(model.getComment());
                viewHolder.setResult(model.getResult());
                viewHolder.setRewarding(model.getRewarding());
                viewHolder.setRewardingP(model.getRewardingP());
                //viewHolder.setImageUrl(getApplicationContext(), model.getImageUrl());
                //viewHolder.setUserName(model.getUsername());
                viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //   Intent singleActivity = new Intent(MainActivity.this, SinglePostActivity.class);
                        //   singleActivity.putExtra("PostID", post_key);
                        //   startActivity(singleActivity);
                    }
                });
            }
        };
        //running signals
        recyclerView.setAdapter(FBRA);
        //closed signals
        recyclerView2.setAdapter(FBRA);
    }

    public static class BlogzoneViewHolder extends RecyclerView.ViewHolder {
        View mView;

        public BlogzoneViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
        }

        public void setPair(String pair) {
            TextView post_pair = mView.findViewById(R.id.quote);
            post_pair.setText(pair);
        }

        public void setBuySell(String buySell) {
            TextView post_buysell = mView.findViewById(R.id.type);
            post_buysell.setText(buySell);
        }

        public void setOpenPrice(String openPrice) {
            TextView post_openprice = mView.findViewById(R.id.entry);
            post_openprice.setText(openPrice);
        }

        public void setTakeProfit(String takeProfit) {
            TextView post_takeprofit = mView.findViewById(R.id.tp);
            post_takeprofit.setText("Tp: " + takeProfit);
        }

        public void setStopLoss(String stopLoss) {
            TextView post_stoploss = mView.findViewById(R.id.sl);
            post_stoploss.setText("Sl: " + stopLoss);
        }

        public void setProfitPips(String profitPips) {
            //nothing
        }

        public void setLossPips(String lossPips) {
            //nothing
        }

        public void setRewardingP(String comment) {
            //nothing
        }

        public void setComment(String comment) {
        //nothing
        }

        public void setRewarding(String rewarding) {
        //nothing
        }

        public void setResult(String result) {
            TextView post_result = mView.findViewById(R.id.status);
            post_result.setText("result");
            if (!post_result.getText().toString().trim().matches("Take Profit Hit")) {
                post_result.setTextColor(Color.parseColor("#ffcc0000"));
            } else if (!post_result.getText().toString().trim().matches("Stop Loss Hit")) {
                post_result.setTextColor(Color.parseColor("#ff669900"));
            } else if (!post_result.getText().toString().trim().matches("Pending...")) {
                post_result.setTextColor(Color.parseColor("#000"));
            } else {
                post_result.setTextColor(Color.parseColor("#ffffff"));
            }
        }
    }}

Help I am stack!帮助我堆栈!

List<Blogzone> openedZones = new ArrayList<>();
List<Blogzone> closedZones = new ArrayList<>();

openedZones.addAll(mDatabase.stream().filter(zone -> zone.isOpened()).collect(Collectors.toList()));
closedZones.addAll(mDatabase.stream().filter(zone -> zone.isClosed()).collect(Collectors.toList()));

FirebaseRecyclerAdapter<Blogzone, BlogzoneViewHolder> FBRAopened = new FirebaseRecyclerAdapter<Blogzone, BlogzoneViewHolder>(
    Blogzone.class,
    R.layout.card_items,
    BlogzoneViewHolder.class,
    openedZones
) {
    ...
}
        
FirebaseRecyclerAdapter<Blogzone, BlogzoneViewHolder> FBRAclosed = new FirebaseRecyclerAdapter<Blogzone, BlogzoneViewHolder>(
    Blogzone.class,
    R.layout.card_items,
    BlogzoneViewHolder.class,
    closedZones
) {
    ...
}
        
//running signals
recyclerView.setAdapter(FBRAopened);
//closed signals
recyclerView2.setAdapter(FBRAclosed);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据 JSF 中的用户角色隐藏一些内容? - How can I hide some content based on user role in JSF? 当文件不存在时,如何从 recyclerview 隐藏删除按钮? - How can I hide Delete button from recyclerview, when the file is not exist? 如何使用 AsyncTask、RecyclerView 和 RecyclerView.Adapter 将手机中的图像获取到 RecyclerView? - How can I use AsyncTask, RecyclerView, and a RecyclerView.Adapter to get images from my phone into my RecyclerView? 我如何查看或隐藏一些数据,取决于是否登录的用户? - How can I view or hide some data depending of user logged in or not? 如何从 swagger spring boot 中隐藏一些参数? - How can hide some parameter from swagger spring boot? 如何根据特定条件在我的 RecyclerView 上为某些项目隐藏 ImageView? - How can I hide an ImageView on my RecyclerView for certain items based on a particular condition? 我如何从recyclerview获取3 textview并将其传递给对话框 - How can i get the 3 textview from recyclerview and pass it to dialogbox 如何从不同的活动向 RecyclerView 添加开关布局? - How can I add a switch layout to a RecyclerView from a different activity? 如何在单独的活动中从RecyclerView打开图像? - How can I open an image from a RecyclerView in a separate activity? 我如何从多个数据库引用中获取相同的recyclerview - How can i fetch the same recyclerview from multiple database references
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM