简体   繁体   English

将片段列表项单击中的解析数据传递到新活动

[英]Passing parse data from fragment list item click to new activity

This code runs when you click on someone in the friends list. 当您在朋友列表中单击某人时,此代码将运行。

ProfileActivity.class is essentialy just a blank list right now. ProfileActivity.class现在只是一个空白列表而已。 I need to know how to get the new ProfileActivity to save the list item that was clicked and then pull all the info on that user from parse and display in new ProfileActivity. 我需要知道如何获取新的ProfileActivity来保存单击的列表项,然后从解析中提取该用户的所有信息并显示在新的ProfileActivity中。 Thanks! 谢谢!

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Intent intent = new Intent(getActivity(), ProfileActivity.class);

    startActivity(intent);
    };

Why don't use bundles ? 为什么不使用捆绑包? You can attach Bundle object to your intent, which then can be retrieve into the ProfileActivity by doing getIntent().getExtras(). 您可以将Bundle对象附加到您的意图,然后可以通过执行getIntent()。getExtras()将其检索到ProfileActivity中。

Look at the bundle here : Bundle 在此处查看捆绑包: 捆绑包

And how to attach it to the intent here : Intent 以及如何将其附加到意图: 意图

Assuming you are reffering to parse.ocm 假设您不喜欢parse.ocm

Wheter using the subclassing feature or not, ParseObjects are unfortunately not serializable nor parcable. 无论是否使用子类化功能,不幸的是ParseObjects都不能序列化或解析。

My current solution is to keep a reference to the 'detail' object in a Singleton object held by Dagger: http://square.github.io/dagger/ 我当前的解决方案是在Dagger持有的Singleton对象中保留对“ detail”对象的引用: http : //square.github.io/dagger/

Thought it is working, I am not happy with this solution. 认为它正在工作,我对这种解决方案不满意。

My suggestion is to look into EventBus https://github.com/greenrobot/EventBus . 我的建议是研究EventBus https://github.com/greenrobot/EventBus I found this great article about it here: http://www.stevenmarkford.com/passing-objects-between-android-activities/ and it looks like it is beautifully easy to implement, performs well too! 我在这里找到了有关此文章的精彩文章: http : //www.stevenmarkford.com/passing-objects-between-android-activities/看起来很容易实现,效果也不错!

Unfortunately I have not yet tried using EventBus, but seems like the way to go. 不幸的是,我还没有尝试使用EventBus,但是似乎要走的路。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM