查看传呼机一次又一次地刷相同的图像

乔希·约格什(Joshi Yogesh)

我一直在应用程序(基于问题的答案)。我已经包括了查看寻呼机来滑动图像,但是它只滑动相同的图像。

调用类的类代码(活动中包含视图寻呼机)

package com.example.joshiyogesh.puzzle;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class ExerciseOneQuestionList extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exercise_one_question_list);
    }

    public void questionOne(View view) {

        Intent intent = new Intent(getApplicationContext(),ExerciseOneQuestions.class);
        intent.putExtra("question_index",0);
        startActivity(intent);
    }
}

ExerciseOneQuestion.java

package com.example.joshiyogesh.puzzle;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class ExerciseOneQuestions extends AppCompatActivity {
    ViewPager viewPager;
    public int questionIndexReceive;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exercise_one_questions);
        questionIndexReceive = getIntent().getIntExtra("question_index",1);
//        questionIndexReceive =Integer.parseInt(getIntent().getStringExtra("question_index"));
        viewPager = (ViewPager)findViewById(R.id.pager);
        PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);
    }
}

寻呼机适配器类

package com.example.joshiyogesh.puzzle;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class PagerAdapter extends FragmentPagerAdapter {
    public PagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        position = new ExerciseOneQuestions().questionIndexReceive;
        Fragments fragments = new Fragments();
        Bundle bundle = new Bundle();
        bundle.putInt("question_no",position);
        fragments.setArguments(bundle);
        return fragments;
    }

    @Override
    public int getCount() {
        return 2;
    }
}

片段类

public class Fragments extends Fragment {
    ImageView imageView;
    @Override
    public View onCreateView(LayoutInflater inflater , ViewGroup container ,
                             Bundle savedInstanceState){

        int [] image_index = {R.drawable.eightypageanswer1,R.drawable.eightypageanswer8};
        Bundle bundle = getArguments();
        int message = bundle.getInt("question_no");
        View rootView = inflater.inflate(R.layout.fragments,container,false);
        imageView = (ImageView) rootView.findViewById(R.id.imageQuestions);
        imageView.setImageResource(image_index[message]);
        return rootView;
    }
}

为了测试目的,我只考虑了两个整数图像,但是它总是刷相同的图像,即第一个图像。

而不是在此处更改ExerciseOneQuestionList.java中的“ question_index” ...

public void questionOne(View view) {

        Intent intent = new Intent(getApplicationContext(),ExerciseOneQuestions.class);
        intent.putExtra("question_index",0);
        startActivity(intent);
    }

不明白为什么它总是显示相同的图像?

弗拉基米尔·乔瓦诺维奇(VladimirJovanović)

似乎问题就在这里

position = new ExerciseOneQuestions().questionIndexReceive;

似乎位置总是设置在相同的数字上。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法一次又一次地在LinkedList中插入相同的元素

Pygame:如何一次又一次地从左到右移动图像

OnNavigationItemsSelected侦听器一次又一次地启动相同的活动

随着鼠标一次又一次地输入相同的链接,执行次数增加

高效的jQuery / JS-避免一次又一次地复制粘贴相同的代码

jQuery在突出显示的段落中,它一次又一次地添加相同的文本

机械手一次又一次地打印相同的字符串

为什么CoreBluetooth一次又一次地发现相同的外围设备?

makefile为不同的对象一次又一次地选择相同的源文件

如何停止在 JavaScript 中一次又一次地调用相同的函数?

一次又一次地从 FB-Messanger Webhook 获取相同的消息

如何在html中重复代码而不一次又一次地写相同的代码

通知被一次又一次地触发

在 Fortran 95 中一次又一次地读取文件的内容

避免一次又一次地从JSON获取数据

Flutter:为什么setState((){})一次又一次地设置数据

如何一次又一次地调用URL

更新状态一次又一次地获取数据后

Azure 容器实例一次又一次地失败

一次又一次地馈送avconv

内核一次又一次地死亡

一次又一次地编辑python脚本文件

Square 一次又一次地改变速度

如何一次又一次地重复(递归)查询?

要重用jQuery函数,使函数一次又一次地使用

如何一次又一次地选择读/写?

init方法在servlet中一次又一次地调用

是否必须一次又一次地定义地图?

Stripe Payment API 一次又一次地发送令牌请求