【问题标题】:how to pass object of person item recycler view to anthor activity如何将个人物品recyclerview的对象传递给另一个活动
【发布时间】:2018-07-16 16:30:25
【问题描述】:

我开始从 clic 项目 recyclerview 上为我的所有人员列表发送数据,但我需要在活动 2 中使用一些信息我只是传递人员的姓名

Nb : 人物对象(id,name,phone,email,post)

这是点击项回收器视图适配器的代码

@覆盖 public void onClick(View v) {

                final Intent intent;

                intent =  new Intent(context, Details_Employee.class);
                employee.set
                intent.putExtra("name",name.getText().toString());
                intent.putExtra("post",post.getText().toString());
                /*intent.putExtra("dept",dept.getText().toString());
                intent.putExtra("codebadge",badge.getText().toString());
                intent.putExtra("mobile",phone.getText().toString());
                intent.putExtra("email",email.getText().toString());

*/ context.startActivity(intent);

【问题讨论】:

  • 首先将 Person 类设为 Parsable 或 Serializable 并放入您的意图中

标签: android


【解决方案1】:

尝试在Activity 2中使用intent类的getExtras()方法

Intent intent = getIntent();
String post= intent.getStringExtra("post");
String name = intent.getStringExtra("name");

【讨论】:

    【解决方案2】:

    最简单的解决方案是让你的 person 对象实现Serializable(或Parcelable)。

    然后,像添加其他数据一样将其传递给意图:

    intent.putExtra("person", person);
    

    【讨论】:

    • 如何检索人名和所有信息!!
    • @joker_7 Person person = (Person) getIntent().getSerializableExtra("person");
    • 当我需要使用人名时,我会做这样的事情??名称=person.getName(); ?
    • @joker_7 是的:)
    • 在活动中我做 Employee employee = (Employee) getIntent().getSerializableExtra("person"); Toast.makeText(Details_Employee.this, "项目名称为 "+employee.getName().toString(), Toast.LENGTH_SHORT).show();在我的适配器类 itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Intent intent; intent = new Intent(context, Details_Employee.class); intent.putExtra("person", employee );
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    相关资源
    最近更新 更多