Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android listview项在下一个活动中单击到页面视图_Android - Fatal编程技术网

Android listview项在下一个活动中单击到页面视图

Android listview项在下一个活动中单击到页面视图,android,Android,在第二个屏幕活动中,我有一个列表视图,其中包含项目苹果、香蕉、橘子 当我点击苹果上的特定项目时,它会导航到详细信息屏幕 这里的输出必须看起来像苹果。若我滑动页面,那个么香蕉和NextSweep存储 苹果-->香蕉-->橙色 但我得到的输出就像苹果-->苹果-->苹果 Intent detailIntent=新意图(SecondScreen.this,Details.class); 星触觉(意向); 公共类MyApplication扩展了应用程序{ ArrayList totalvalue=新的A

在第二个屏幕活动中,我有一个列表视图,其中包含项目苹果、香蕉、橘子 当我点击苹果上的特定项目时,它会导航到详细信息屏幕

这里的输出必须看起来像苹果。若我滑动页面,那个么香蕉和NextSweep存储

苹果-->香蕉-->橙色

但我得到的输出就像苹果-->苹果-->苹果

Intent detailIntent=新意图(SecondScreen.this,Details.class);
星触觉(意向);
公共类MyApplication扩展了应用程序{
ArrayList totalvalue=新的ArrayList();
}
公共类详细信息扩展了碎片活动{
我的应用程序;
查看寻呼机;
MyFragmentPagerAdapter pagerAdapter;
公共静态位置;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.detail);
app=((MyApplication)getApplicationContext());
pager=(ViewPager)findViewById(R.id.pager);
FragmentManager fm=getSupportFragmentManager();
pagerAdapter=新的MyFragmentPagerAdapter(fm,app.totalvalue);
寻呼机设置适配器(pagerAdapter);
}
公共静态类MyFragmentPagerAdapter扩展了FragmentPagerAdapter{
私有静态数组列表;
公共MyFragmentPagerAdapter(FragmentManager fm,ArrayList totalvalue){
超级(fm);
this.temperList=总值;
}
公共片段getItem(int位置){
返回ThingFragment.newInstance((temperList.get(position));
}
@凌驾
public int getCount(){
返回temperList.size();
}
私有静态类ThingFragment扩展了片段{
私有字符串名称1;
静态ThingFragment newInstance(字符串){
ThingFragment f=新ThingFragment();
Bundle args=新Bundle();
args.putString(“name”,temperList.get(position));
f、 设置参数(args);
返回f;
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
name1=getArguments().getString(“名称”);
}
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
视图v=充气机。充气(R.layout.myfragment\u布局,容器,假);
TextView t=(TextView)v.findviewbyd(R.id.prodcutt);
t、 setText(“+name1”);
返回v;
}
}
}
}
args.putString(“name”,temperList.get(position))
不应该在
ThingFragment
中作为其静态

应该是
args.putString(“name”,string)

另外,您的
temperList
在适配器中不应该是静态的(没有理由,您将其作为参数传递),只需将其设置为
final
-
private final ArrayList temperList

如果这还不能解决问题,请发布更多结构化的分离代码,这样我们就可以更多地了解您的应用程序是如何构建的。适配器看起来很好,因此您可能需要在某个时候写入/覆盖数组

  Intent detailIntent =new Intent(SecondScreen.this, Details.class);            

    startActivity(detailIntent);


    public class MyApplication extends Application {

        ArrayList<String> totalvalue  = new ArrayList<String>();

    }


    public class Details extends FragmentActivity{

        MyApplication app;
        ViewPager pager;
      MyFragmentPagerAdapter pagerAdapter;     
     public static int position ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.detail);    
        app = ((MyApplication) getApplicationContext());
        pager = (ViewPager) findViewById(R.id.pager);

        FragmentManager fm = getSupportFragmentManager();      
        pagerAdapter = new MyFragmentPagerAdapter(fm,app.totalvalue);   
          pager.setAdapter(pagerAdapter);

      }



    public static class MyFragmentPagerAdapter extends FragmentPagerAdapter {


        private static  ArrayList<String> temperList;



        public MyFragmentPagerAdapter(FragmentManager fm, ArrayList<String> totalvalue ) {
             super(fm);
             this.temperList = totalvalue;
        }


        public Fragment getItem(int position) {

            return ThingFragment.newInstance((temperList.get(position)));
        }

        @Override
        public int getCount(){

        return temperList.size();

        }

         private static class ThingFragment extends Fragment {       
                private String name1;
             static ThingFragment newInstance(String string ) {

                    ThingFragment f = new ThingFragment();
                    Bundle args = new Bundle();

            args.putString("name",temperList.get(position) );
                    f.setArguments(args);

                    return f;
                }



                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    name1 = getArguments().getString("name");
                }

                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container,                       Bundle savedInstanceState) {

                    View v = inflater.inflate(R.layout.myfragment_layout, container, false);
                    TextView t = (TextView)v.findViewById(R.id.prodcutt);
                    t.setText(""+ name1);
                    return v;
            }

        }

    }


    }