简体   繁体   English

在Serializable类中传递对象捆绑意图

[英]Passing object Bundle intent in Serializable class

I must mention i am new to Android and Java. 我必须提到我是Android和Java的新手。 I am trying this for a weeek to solve. 我正在尝试解决这个问题。 I have Serializable class wich object are populated with http json, and i am using adapters to populate listviews and everything works fine but when i want to pass to another class one object i it force closes, please if somebody can correct my code. 我有Seri​​alizable类,其中的对象填充了http json,并且我正在使用适配器填充列表视图,并且一切正常,但是当我想传递给另一个类时,它会强制关闭,如果有人可以纠正我的代码,请关闭该对象。

this void is in Serializable class 此void在Serializable类中

  public void save(){
 Intent intent =  new Intent();
 Bundle extra = intent.getExtras();
  intent.putExtra("title", getTitle()); 

           }

when i try this: 当我尝试这个:

Intent intent =  new Intent(this, Fragment2.class);  i got error The constructor   
Intent(FeedItem, Class<Fragment2>) is undefined

and this is fragment class where i want to use passed object 这是片段类,我想使用传递的对象

     Intent intent = getActivity().getIntent();
 Bundle extras = intent.getExtras();
 FeedItem feedItem = (FeedItem)getActivity().getIntent().getSerializableExtra("title");
 String title = feedItem.getTitle();
 Toast.makeText(getActivity(), title, Toast.LENGTH_LONG).show(); 

error The value of the local variable extras is not used 错误未使用局部变量extras的值

Many thanks. 非常感谢。

Fragments are added like this 像这样添加片段

FragmentTransaction ft = getSupportFragmentManager()
                    .beginTransaction();
            ft.replace(resourceidwhereyouwantadd(R.id.view), new YourFragment());
            ft.commit();

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

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