0

ユーザーがスワイプジェスチャを使用してタブを切り替えることができるタブベースのビューを実装しようとしています。ただし、スワイプで同じアクティビティの複数のインスタンスが開きます。どうすればこれを防ぐことができますか? ありがとう

public boolean onTouch(View v, MotionEvent event) {
    switch(event.getAction() & MotionEvent.ACTION_MASK){

    case MotionEvent.ACTION_DOWN:
        initialx=event.getX();
        initialy=event.getY();
        break;

    case MotionEvent.ACTION_UP:
        break;

    case MotionEvent.ACTION_MOVE:
        finalx=event.getX();
        finaly=event.getY();

        if (initialx>(finalx+150.0)){

            RadioGroup Options = (RadioGroup) findViewById(R.id.vOptions);
            int selectedId = Options.getCheckedRadioButtonId();
            final EditText QuestionNo = (EditText)findViewById(R.id.vnumberofquestions);
            final EditText Time = (EditText)findViewById(R.id.vtimeperquestion);

            if ((QuestionNo.getText().toString().equals(" ")) || (Time.getText().toString().equals("")) ||(selectedId==-1)) { 
                Intent intenta=new Intent(VerbalSelect.this, TabDisplay.class );
                intenta.putExtra("index", 0);
                startActivity(intenta);
            }
            else {   
                RadioButton selectedButton = (RadioButton) findViewById(selectedId);
                String testtype = (String) selectedButton.getText(); 
                int questionno = Integer.parseInt(QuestionNo.getText().toString());
                int timeperquestion = Integer.parseInt(Time.getText().toString());
                long timeroffset = questionno*timeperquestion;
                Intent intent=new Intent(VerbalSelect.this, Main.class);

                intent.putExtra("testtype", testtype);
                intent.putExtra("timeroffset",timeroffset);
                intent.putExtra("questionno","1");
                intent.putExtra("questionlimit", questionno);
                startActivity(intent);
            }
            break;
        }
    }
    return true;
}
4

1 に答える 1

0

ViewPagerAndroidサポートライブラリをご覧ください。標準のAndroidデバイスに表示されるこのフォームのほとんどのUIは、このコンポーネントを使用します。

各ページはFragment、完全なアクティビティではなく、ビューのレイアウトとして実装されます。これにより、ページ間のスワイプとアニメーションがきれいになり、複数のアクティビティの問題が回避されます。

タブとの統合を提供するには、そのまま使用できます。PagerTabStrip従来のスタイルのタブについては、SDKに含まれているSupport4Demosサンプルのコード例を参照してください。<sdk>/extras/android/compatibility/v4/samples/Support4DemosSDKをインストールした場所ならどこでも見つけることができます。デモはFragmentTabsPagerあなたが探しているものです。

于 2012-08-26T18:17:20.087 に答える