Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.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 按钮不执行其编程的操作_Android - Fatal编程技术网

Android 按钮不执行其编程的操作

Android 按钮不执行其编程的操作,android,Android,我有两个if语句,其中if modechoiceId == R.id.textmode && sizechoiceId == R.id.normal -- 1 或 (1)将使下一个按钮转到一个新的活动,即textmode32by32.class和 (2)将使下一个按钮转到一个新活动,即animationmode32by32.class 现在的问题是,这两个选项将转到同一个页面,即textmode32by32.class 问题是否出在放射组?或者代码在if语句中 起始页类 pa

我有两个if语句,其中if

modechoiceId == R.id.textmode && sizechoiceId == R.id.normal -- 1

(1)将使下一个按钮转到一个新的活动,即textmode32by32.class和 (2)将使下一个按钮转到一个新活动,即animationmode32by32.class

现在的问题是,这两个选项将转到同一个页面,即textmode32by32.class

问题是否出在放射组?或者代码在if语句中


起始页类

package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

public class startPage extends Activity {

    Button backButton, nextButton;
    RadioGroup modeselection, sizeselection;

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

        nextButton = (Button) findViewById(R.id.nextselection);
        backButton = (Button) findViewById(R.id.backselection);
        modeselection = (RadioGroup) findViewById(R.id.modeselection);
        sizeselection = (RadioGroup) findViewById(R.id.sizeselection);

        int modechoiceId = modeselection.getCheckedRadioButtonId();
        int sizechoiceId = sizeselection.getCheckedRadioButtonId();

        if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

            nextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent nextSelection = new Intent(startPage.this, textmode32by32.class);
                    startActivity(nextSelection);

                }
            });

        }

        else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

            nextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                    startActivity(nextSelection1);

                }
            });

        }

        backButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent backSelection = new Intent(startPage.this, MainActivity.class);
                startActivity(backSelection);

            }
        });




    }

}
package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class animationmode32by32 extends Activity {

    Button nextBtn, backBtn;

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

        backBtn = (Button) findViewById(R.id.backBtn2);

        backBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent backSelection = new Intent(animationmode32by32.this, startPage.class);
                startActivity(backSelection);

            }
        });

    }

}
package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.SeekBar;

public class textmode32by32 extends Activity {

    Button nextBtn, backBtn;
    RadioButton left, stagnant, right;
    SeekBar scrollspeed;

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

    backBtn = (Button) findViewById(R.id.backBtn1);

    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent backBtn = new Intent(textmode32by32.this, startPage.class);
            startActivity(backBtn);

        }
    });



    }



}
动画模式32by32.class

package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

public class startPage extends Activity {

    Button backButton, nextButton;
    RadioGroup modeselection, sizeselection;

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

        nextButton = (Button) findViewById(R.id.nextselection);
        backButton = (Button) findViewById(R.id.backselection);
        modeselection = (RadioGroup) findViewById(R.id.modeselection);
        sizeselection = (RadioGroup) findViewById(R.id.sizeselection);

        int modechoiceId = modeselection.getCheckedRadioButtonId();
        int sizechoiceId = sizeselection.getCheckedRadioButtonId();

        if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

            nextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent nextSelection = new Intent(startPage.this, textmode32by32.class);
                    startActivity(nextSelection);

                }
            });

        }

        else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

            nextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                    startActivity(nextSelection1);

                }
            });

        }

        backButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent backSelection = new Intent(startPage.this, MainActivity.class);
                startActivity(backSelection);

            }
        });




    }

}
package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class animationmode32by32 extends Activity {

    Button nextBtn, backBtn;

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

        backBtn = (Button) findViewById(R.id.backBtn2);

        backBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent backSelection = new Intent(animationmode32by32.this, startPage.class);
                startActivity(backSelection);

            }
        });

    }

}
package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.SeekBar;

public class textmode32by32 extends Activity {

    Button nextBtn, backBtn;
    RadioButton left, stagnant, right;
    SeekBar scrollspeed;

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

    backBtn = (Button) findViewById(R.id.backBtn1);

    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent backBtn = new Intent(textmode32by32.this, startPage.class);
            startActivity(backBtn);

        }
    });



    }



}
textmode32by32.class

package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

public class startPage extends Activity {

    Button backButton, nextButton;
    RadioGroup modeselection, sizeselection;

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

        nextButton = (Button) findViewById(R.id.nextselection);
        backButton = (Button) findViewById(R.id.backselection);
        modeselection = (RadioGroup) findViewById(R.id.modeselection);
        sizeselection = (RadioGroup) findViewById(R.id.sizeselection);

        int modechoiceId = modeselection.getCheckedRadioButtonId();
        int sizechoiceId = sizeselection.getCheckedRadioButtonId();

        if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

            nextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent nextSelection = new Intent(startPage.this, textmode32by32.class);
                    startActivity(nextSelection);

                }
            });

        }

        else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

            nextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                    startActivity(nextSelection1);

                }
            });

        }

        backButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent backSelection = new Intent(startPage.this, MainActivity.class);
                startActivity(backSelection);

            }
        });




    }

}
package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class animationmode32by32 extends Activity {

    Button nextBtn, backBtn;

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

        backBtn = (Button) findViewById(R.id.backBtn2);

        backBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent backSelection = new Intent(animationmode32by32.this, startPage.class);
                startActivity(backSelection);

            }
        });

    }

}
package tp.mp2014.dotmatrix;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.SeekBar;

public class textmode32by32 extends Activity {

    Button nextBtn, backBtn;
    RadioButton left, stagnant, right;
    SeekBar scrollspeed;

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

    backBtn = (Button) findViewById(R.id.backBtn1);

    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent backBtn = new Intent(textmode32by32.this, startPage.class);
            startActivity(backBtn);

        }
    });



    }



}
selectionmode.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1H"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textmodeselection"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textmodeselection"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textsizeselection"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="@string/textsizeselection"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </LinearLayout>

    <RadioGroup
        android:id="@+id/sizeselection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/modeselection"
        android:layout_toRightOf="@+id/modeselection" >

        <RadioButton
            android:id="@+id/normal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/sizechoice1" />

        <RadioButton
            android:id="@+id/extended"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sizechoice2" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/modeselection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/LinearLayout1H" >

        <RadioButton
            android:id="@+id/textmode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/modechoice1" />

        <RadioButton
            android:id="@+id/animationmode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/modechoice2" />

        <RadioButton
            android:id="@+id/imagemode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/modechoice3" />
    </RadioGroup>

    <Button
        android:id="@+id/backselection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/back" />

    <Button
        android:id="@+id/nextselection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/next" />

</RelativeLayout>

像这样试试

nextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            int modechoiceId = modeselection.getCheckedRadioButtonId();
            int sizechoiceId = sizeselection.getCheckedRadioButtonId();
            if (modechoiceId == R.id.textmode
                    && sizechoiceId == R.id.normal) {

                //first
            } else if (modechoiceId == R.id.animationmode
                    && sizechoiceId == R.id.normal) {

                //second activity
            }

        }
    });

问题是,当
startPage
活动启动时,它会将按钮侦听器onclick直接设置为
if(modechoiceId==R.id.textmode&&sizechoiceId==R.id.normal)

为什么?

因为每次选中另一个单选按钮时,您不会更改它

解决方案:

if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

        nextButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent nextSelection = new Intent(startPage.this, textmode32by32.class);
                startActivity(nextSelection);

            }
        });

    }

    else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

        nextButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                startActivity(nextSelection1);

            }
        });

    }
 nextButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                int modechoiceId = modeselection.getCheckedRadioButtonId();
                int sizechoiceId = sizeselection.getCheckedRadioButtonId();

                if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

                   Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                   startActivity(nextSelection1);

        }

                else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

                    Intent backSelection = new Intent(startPage.this, MainActivity.class);
            startActivity(backSelection);
}
                }
            });
将检查单选按钮置于onclick侦听器中

更改此选项:

if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

        nextButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent nextSelection = new Intent(startPage.this, textmode32by32.class);
                startActivity(nextSelection);

            }
        });

    }

    else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

        nextButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                startActivity(nextSelection1);

            }
        });

    }
 nextButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                int modechoiceId = modeselection.getCheckedRadioButtonId();
                int sizechoiceId = sizeselection.getCheckedRadioButtonId();

                if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

                   Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                   startActivity(nextSelection1);

        }

                else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

                    Intent backSelection = new Intent(startPage.this, MainActivity.class);
            startActivity(backSelection);
}
                }
            });
至:

if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

        nextButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent nextSelection = new Intent(startPage.this, textmode32by32.class);
                startActivity(nextSelection);

            }
        });

    }

    else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

        nextButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                startActivity(nextSelection1);

            }
        });

    }
 nextButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                int modechoiceId = modeselection.getCheckedRadioButtonId();
                int sizechoiceId = sizeselection.getCheckedRadioButtonId();

                if(modechoiceId == R.id.textmode && sizechoiceId == R.id.normal){

                   Intent nextSelection1 = new Intent(startPage.this, animationmode32by32.class);
                   startActivity(nextSelection1);

        }

                else if(modechoiceId == R.id.animationmode && sizechoiceId == R.id.normal){

                    Intent backSelection = new Intent(startPage.this, MainActivity.class);
            startActivity(backSelection);
}
                }
            });

你能发布你的selectionmode.xml吗code@madhu-已经添加了。工作正常。介意解释一下吗?我的代码和你的代码主要是什么?我还是不明白。你可以为一个按钮定义多个监听器,但程序总是执行第一个监听器。