How to pass bean class one activity to another activity on android

前端 未结 4 1934
情书的邮戳
情书的邮戳 2021-01-16 11:25

Hi this is my listview onClicklister.

when i click the list item , I pass the the arraylist which is getting from bean class one activity to another activity like

4条回答
  •  不知归路
    2021-01-16 11:59

    Yes you can do that by in1.putExtra("beanObject", bean).

    public void onItemClick(AdapterView arg0, View arg1,
                    int position, long id) {
    
                bean = (ActivitiesBean) adapter.getItem(position); //ActivitiesBean is the name of the bean class
    
                Intent in1 = new Intent(firstclass.this, secondclass.class);
                in1.putExtra("beanObject", bean);
                startActivity(in1);
            }
    
        });
    

    and use this for the secondclass.java

    ActivitiesBean bean =  (ActivitiesBean) getIntent().getSerializableExtra("beanObject");
    txt_title.setText(bean.getTitle());  //txt_title is the object of the textview 
    

提交回复
热议问题