我想从几个角度动态地获取输入。我该怎么做?

时间:2018-06-21 09:00:32

标签: android arrays firebase arraylist firebase-realtime-database

因此,我的应用程序中有一个活动,我需要输入从后端检索到的不同票证类别的票证数量。票证类别的数量也是可变的。在这种情况下,我该如何接受用户输入?每次按下countdown_btn或countup_btn时,我需要更新一个数组,该数组保存用户选择的票证数量。票证类别本身是动态的时候该怎么办?

如果单击按钮“质押”,我想从此处的每个视图中获取相应的输入,并以某种方式将其传达给下一个活动。

我的应用代码:

public class RewardsAndPledgeActivity extends AppCompatActivity {

    DatabaseReference mRewardsRef;
    RecyclerView rewards_list;
    String Artcall_id;
    String reward_id[];
    Integer counter = 0;

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


        /* -------- Obtain the Event ID of the item that the user has selected on the RecyclerView ------*/
        Intent intent = getIntent();
        Artcall_id  = intent.getStringExtra("Artcall_id");
        /* ----------------------------------------------------------------------------------------------*/

        mRewardsRef = FirebaseDatabase.getInstance().getReference().child("Rewards").child(Artcall_id);
        rewards_list = (RecyclerView) findViewById(R.id.reward_list);

        rewards_list.setHasFixedSize(true);
        rewards_list.setLayoutManager(new LinearLayoutManager(this));
    }



    @Override
    protected void onStart() {
        super.onStart();


        FirebaseRecyclerAdapter<Reward_List, RewardsViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Reward_List, RewardsViewHolder>(
                Reward_List.class,
                R.layout.single_reward_item_layout,
                RewardsAndPledgeActivity.RewardsViewHolder.class,
                mRewardsRef
        ) {
            @Override
            protected void populateViewHolder(final RewardsViewHolder viewHolder, Reward_List model, int position) {
                final String reward_id = getRef(position).getKey();

                viewHolder.setReward_ticket_amount_txt(model.getReward_ticket_amount_txt());
                viewHolder.setReward_ticket_amount_class_name(model.getReward_ticket_amount_class_name());
                viewHolder.setReward_ticket_class_desc(model.getReward_ticket_class_desc());

                viewHolder.countdown_btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Integer current_ticket_count = Integer.parseInt(viewHolder.ticket_counter.getText().toString());
                        if(current_ticket_count >0 ) {
                            viewHolder.ticket_counter.setText(String.valueOf(current_ticket_count - 1));
                        }
                    }
                });

                viewHolder.countup_btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Integer current_ticket_count = Integer.parseInt(viewHolder.ticket_counter.getText().toString());
                        viewHolder.ticket_counter.setText(String.valueOf(current_ticket_count + 1));

                    }
                });


            }
        };

            rewards_list.setAdapter(firebaseRecyclerAdapter);

    }


}

我的数据库: enter image description here

活动图片: enter image description here

0 个答案:

没有答案