如何在另一个活动中滑动时增加ArrayList的位置

时间:2016-02-20 04:31:06

标签: java android android-studio

我练习一个应用程序。我在其中制作了一个放置数组,一个网格视图,显示GridView中的第0个位置和ImageView中第一个位置的网格视图,在另一个名为answer的活动中点击gridview时显示第二个位置。在刷卡时回答活动我希望它转到另一个问题,但我没有得到它。你可以帮帮我吗。下面是代码。

public class QuestionsActivity extends Activity {
    public Place[] myPlaceArray = new Place[]{
        new Place(1, "settings" , "1. Given the choice of"),
        new Place(2, "settings" , "2. Would you like to "),
        new Place(3, "settings" , "3. Before making a telephone call"),
        new Place(4, "settings" , "4. What would constitute "),
        new Place(5, "settings" , "5. When did you last"),
        new Place(6, "settings" , "6. If you were "),
        new Place(7, "settings" , "7. Do you have a secret "),
        new Place(8, "settings" , "8. Name three things you "),
        new Place(9, "settings" , "9. For what in your "),
        new Place(10, "settings" , "10. If you could ")
    };

    private GridView numgridView;
    private ArrayAdapter mPlaceAdapter;
    public int clickedPosition;

    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.question_activity);

        numgridView = (GridView) findViewById(R.id.numGrid);
        mPlaceAdapter = new PlaceAdapter(getApplicationContext(),R.layout.question_numbers_view,myPlaceArray);

        if (numgridView!=null){
            numgridView.setAdapter(mPlaceAdapter);
        }
        numgridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                clickedPosition = position;
                Log.v("PLACE", myPlaceArray[position].Question);
                Intent intent = new Intent(QuestionsActivity.this, answer.class);
                intent.putExtra("theAnswer",myPlaceArray[position].Question );

                intent.putExtra("theNextAnswer",myPlaceArray[clickedPosition ++].Question ); // this is what i tried but it dint work
                intent.putExtra("thePreviousAnswer",myPlaceArray[clickedPosition --].Question ); // this is what i tried but it dint work

                startActivity(intent);
                Toast.makeText(QuestionsActivity.this, "Touch And Hold To Copy The Text",
                        Toast.LENGTH_LONG).show();
            }
        });
    }
}

我把它传递给另一个带钥匙的活动,当我刷它时我希望它转到下一个问题。

public class answer extends Activity implements AdColonyAdAvailabilityListener, AdColonyAdListener {
    TextView textView;
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.answer);
    AdColony.configure(this, "version:1.0,store:google", APP_ID, ZONE_ID);
    AdColony.addAdAvailabilityListener(this);
    textView = (TextView) findViewById(R.id.answer);
    textView.setText(getIntent().getExtras().getString("theAnswer"));
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
        }
    });
    textView.setOnTouchListener(new OnSwipeTouchListener() {
        public boolean onSwipeRight() {
            Toast.makeText(answer.this, "right", Toast.LENGTH_SHORT).show();
            textView.setText(getIntent().getExtras().getString("thePreviousAnswer"));
            return true;
            // here when i swiped i want it to go to next question
        }
            public boolean onSwipeLeft() {
                Toast.makeText(answer.this, "left", Toast.LENGTH_SHORT).show();
                textView.setText(getIntent().getExtras().getString("theNextAnswer"));
                return true;
                //here i want it go to previous question 
            }
        });
    if(AdColony.statusForZone(ZONE_ID).equals("active"))
    {
        textView.setEnabled( true );
    }
}

0 个答案:

没有答案