zoukankan      html  css  js  c++  java
  • Intent 传递对象

    方法:

    可以让这个要传递的对象所属类实现Serializable或者Parcelable接口,

    然后利用onCreate函数中的Bundle参数作为载体,传递这个对象。

    例如:

    <span style="font-size:14px;color: rgb(75, 75, 75);">
            @Override 
            public void onItemClick(AdapterView<?> parent, View view, int position, long i) 
            { 
                User user= (User) Connect.getUser(position); 
                Intent intent = new Intent(Activity1.this,Activity2.class); 
                Bundle bundle = new Bundle(); 
                bundle.putSerializable("USER", user); 
                intent.putExtras(bundle); 
                startActivity(intent); 
        
            } 
        }
    
    
     
    
     
    
    在接收对象的地方:
    
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.detail); 
        User </span><span style="color: rgb(75, 75, 75); font-size: 13px; font-family: georgia, verdana, Arial, helvetica, sans-seriff;">user</span><span style="color: rgb(75, 75, 75); font-size: 13px; font-family: georgia, verdana, Arial, helvetica, sans-seriff;">= (Item) getIntent().getSerializableExtra("user"); </span><span style="font-size:14px;color: rgb(75, 75, 75);">
        //这里就得到user对象了,注意:必须确保user</span><span style="font-family: georgia, verdana, Arial, helvetica, sans-seriff; line-height: 19.5px;"><span style="font-size:12px;color:#666666;">类实现Serializable或者Parcelable接口</span></span><span style="font-size:14px;color: rgb(75, 75, 75);">
    }</span>


  • 相关阅读:
    学习笔记TF034:实现Word2Vec
    学习笔记TF033:实现ResNet
    学习笔记TF032:实现Google Inception Net
    学习笔记TF031:实现VGGNet
    学习笔记TF030:实现AlexNet
    学习笔记TF029:实现进阶卷积网络
    学习笔记TF028:实现简单卷积网络
    学习笔记TF027:卷积神经网络
    学习笔记TF026:多层感知机
    学习笔记TF025:自编码器
  • 原文地址:https://www.cnblogs.com/jasonkent27/p/4098422.html
Copyright © 2011-2022 走看看