0

Hy Guys...助けてください..前のボタンをクリックするたびに1つずつ戻る必要があります.回、クリックするたびに前に移動し、もう一度前に移動し、もう一度前に移動します。

xml コード

<TextView
    android:id="@+id/tvSTNN"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="19dp"
    android:text="1"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#F2416B"
    android:textSize="150sp" />

<TextView
    android:id="@+id/tvSTN"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvSTNN"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="33dp"
    android:text="ONE"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#F2416B"
    android:textSize="100sp" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_marginTop="400dp"
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnRestart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="Restart"
         />

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="Next"
         />

    <Button 
        android:id="@+id/btnPrevious"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="Previous"
        />
</LinearLayout>

Java コード

package com.newApp.textfield;


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SpellToNumbers extends Activity implements View.OnClickListener{


    Button btn_Next;
    Button btnRestart;
    Button btn_previous;
    TextView tvSTN, tvSTNN;
    int a;
    RelativeLayout stnXML;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    setContentView(R.layout.spell_to_numbers);
    tvSTN = (TextView) findViewById(R.id.tvSTN);
    tvSTNN = (TextView) findViewById(R.id.tvSTNN);
    stnXML = (RelativeLayout) findViewById(R.id.stnXML);
    btn_Next = (Button) findViewById(R.id.btnNext);
    btn_Next.setOnClickListener(this);
    btnRestart = (Button) findViewById(R.id.btnRestart);
    btnRestart.setOnClickListener(this);
    btn_previous = (Button) findViewById(R.id.btnPrevious);
    btn_previous.setOnClickListener(this);
    }//onCreate end



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;

    }//onCreateOptionMenu end


        @Override
        public void onClick(View v) {
            switch (v.getId())
            {
                case R.id.btnRestart:
                    tvSTNN.setText("1");
                    tvSTN.setText("ONE");
                    tvSTNN.setTextColor(Color.parseColor("#F2416B"));
                    tvSTN.setTextColor(Color.parseColor("#F2416B"));
                    stnXML.setBackgroundColor(Color.parseColor("#3FD161"));
                    a = 0;

                    break;

                case R.id.btnNext:
                    if (a == 0)
                    {
                        tvSTNN.setText("2");
                        tvSTNN.setTextColor(Color.parseColor("#F0EFDA"));
                        tvSTN.setText("TWO");
                        tvSTN.setTextColor(Color.parseColor("#F0EFDA"));
                        stnXML.setBackgroundColor(Color.parseColor("#0A0EF5"));
                        a = 1; 
                    }

                    else if (a == 1)
                    {                       
                        tvSTNN.setText("3");
                        tvSTNN.setTextColor(Color.parseColor("#F5F507"));
                        tvSTN.setText("THREE");
                        tvSTN.setTextColor(Color.parseColor("#F5F507"));
                        stnXML.setBackgroundColor(Color.parseColor("#D15BE3"));
                        a = 2;
                    }
                    else if (a == 2)
                    {                       
                        tvSTNN.setText("4");
                        tvSTNN.setTextColor(Color.parseColor("#0AF5DD"));
                        tvSTN.setText("FOUR");
                        tvSTN.setTextColor(Color.parseColor("#0AF5DD"));
                        stnXML.setBackgroundColor(Color.parseColor("#F50A0A"));
                        a = 3;
                    }
                    else if (a == 3)
                    {                       
                        tvSTNN.setText("5");
                        tvSTNN.setTextColor(Color.parseColor("#171117"));
                        tvSTN.setText("FIVE");
                        tvSTN.setTextColor(Color.parseColor("#171117"));
                        stnXML.setBackgroundColor(Color.parseColor("#0AF5DD"));
                        a = 4;
                    }
                    else if (a == 4)
                    {                       
                        tvSTNN.setText("6");
                        tvSTNN.setTextColor(Color.parseColor("#072BF5"));
                        tvSTN.setText("SIX");
                        tvSTN.setTextColor(Color.parseColor("#072BF5"));
                        stnXML.setBackgroundColor(Color.parseColor("#0AF525"));
                        a = 5;
                    }
                    else if (a == 5)
                    {                       
                        tvSTNN.setText("7");
                        tvSTNN.setTextColor(Color.parseColor("#8F0AF5"));
                        tvSTN.setText("SEVEN");
                        tvSTN.setTextColor(Color.parseColor("#8F0AF5"));
                        stnXML.setBackgroundColor(Color.parseColor("#F5F10A"));
                          a = 6;
                    }
                    else if (a == 6)
                    {                       
                        tvSTNN.setText("8");
                        tvSTNN.setTextColor(Color.parseColor("#37F507"));
                        tvSTN.setText("EIGHT");
                        tvSTN.setTextColor(Color.parseColor("#37F507"));
                        stnXML.setBackgroundColor(Color.parseColor("#9C2497"));
                         a = 7;
                    }
                    else if (a == 7)
                    {                       
                        tvSTNN.setText("9");
                        tvSTNN.setTextColor(Color.parseColor("#F50707"));
                        tvSTN.setText("NINE");
                        tvSTN.setTextColor(Color.parseColor("#F50707"));    
                        stnXML.setBackgroundColor(Color.parseColor("#BAF50A"));
                        a = 8;
                    }
                    else if (a == 8)
                    {
                        tvSTNN.setText("10");
                        tvSTNN.setTextColor(Color.parseColor("#0ACAF5"));
                        tvSTN.setText("TEN");
                        tvSTN.setTextColor(Color.parseColor("#0ACAF5"));
                        stnXML.setBackgroundColor(Color.parseColor("#F5700A"));
                        tvSTN.setClickable(false);   
                    }

                    break;


                case R.id.btnPrevious:

                    a--;

                    btn_Next.performClick();


                        break;
            }//switch end


        }//onClick end

    }//class end
4

2 に答える 2

0

まず、aグローバルに宣言した変数の値を初期化していません。a再起動ボタンのクリック時のみ値を初期化したようです。ただし、再起動ボタンをクリックした後にのみ手順を開始する場合は、問題はありません。

ただし、少なくとも初期化する方がよいでしょ0a

于 2013-10-25T10:11:09.257 に答える