gpt4 book ai didi

android - fragmentActivity setarguments 无法解析

转载 作者:行者123 更新时间:2023-11-30 01:39:47 26 4
gpt4 key购买 nike

我正在关注这个SO answer .但是我在这一行上有错误 cannot resolve method setarguments

          details.setArguments(getIntent().getExtras());

这是代码

public class SingleViewActivity extends FragmentActivity {

MyPageAdapter pageAdapter;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page_view);

List<Fragment> fragments = getFragments();

if (savedInstanceState == null) {
// During initial setup, plug in the details fragment.
MainActivity details = new MainActivity();
details.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(android.R.id.content, details).commit();
}
/*
pageAdapter = new MyPageAdapter (getSupportFragmentManager(), fragments);
ViewPager pager=(ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);*/
// pageAdapter = new MyPageAdapter (getSupportFragmentManager(), fragments);
ViewPager pager=(ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);
}
private List<Fragment> getFragments() {
List<Fragment> flist = new ArrayList<Fragment>();

flist = new ArrayList<Fragment>();

flist.add(MyFragment.newInstance("frag1"));
flist.add(MyFragment.newInstance("frag2"));
flist.add(MyFragment.newInstance("frag3"));
return flist;
}
public static class MyPageAdapter extends PagerAdapter {
//private List<Fragment> fragments;
Context mContext;
LayoutInflater mLayoutInflater;

public MyPageAdapter(Context context)
{
mContext = context;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}
@Override
public boolean isViewFromObject(View view, Object object)
{
return view ==((LinearLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position)
{

View itemView =mLayoutInflater.inflate(R.layout.pager_item,container,false);
ImageView imageView= (ImageView) itemView.findViewById(R.id.viewpager);
String Item = getActivity().getIntent().getExtras().getString("name");

Bundle bundle = this.getArguments();

//Bundle bundle = getIntent().getExtras();

ArrayList<Listitem> personArrayList = bundle.getParcelableArrayList("Person_List");

if (personArrayList != null && !personArrayList.isEmpty()) {
for (Listitem person : personArrayList) {
Picasso.
with(this).
load(person.url)
.placeholder(R.drawable.logo)
.fit()
.noFade()
.into(imageView);
Log.i("PersonsActivity",String.valueOf(person.url));
}
}

imageView.setImageResource();
container.addView(itemView);
return itemView;
}

@Override
public int getCount()
{
return this.fragments.size();
}
}

}

最佳答案

在您提供的链接中,setArguments() 是针对 fragment 而非 Activity 调用的。

在您的代码中,您尝试将 Activity 添加为 fragment :

MainActivity details = new MainActivity();
details.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(android.R.id.content, details).commit();

定义一个 fragment 以添加到 SingleViewActivity 并改用它。

关于android - fragmentActivity setarguments 无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34640813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com