Android layout Android:将按钮移动到不同的LinearLayout会搞乱点击事件

Android layout Android:将按钮移动到不同的LinearLayout会搞乱点击事件,android-layout,button,view,onclick,android-linearlayout,Android Layout,Button,View,Onclick,Android Linearlayout,我从事专业开发已经超过14年了,但我正在学习Android开发。我遇到了一个让我难以置信的情景。我设计了一个简单的布局,然后决定将一些按钮从一个LinearLayout移动到同一布局文件中的另一个LinearLayout 现在,由于移动了按钮,点击事件被连接到错误的按钮!这就好像按钮的资源ID是顺序相关的 在(正常工作)之前: 因此,这些资源ID必须是特定于订单的;我无法用其他方式解释。问题是我不知道如何让我的按钮在我想要的布局中发挥作用。好的,我想我已经解决了。在Eclipse/ADT中,我进

我从事专业开发已经超过14年了,但我正在学习Android开发。我遇到了一个让我难以置信的情景。我设计了一个简单的布局,然后决定将一些按钮从一个LinearLayout移动到同一布局文件中的另一个LinearLayout

现在,由于移动了按钮,点击事件被连接到错误的按钮!这就好像按钮的资源ID是顺序相关的

在(正常工作)之前:


因此,这些资源ID必须是特定于订单的;我无法用其他方式解释。问题是我不知道如何让我的按钮在我想要的布局中发挥作用。

好的,我想我已经解决了。在Eclipse/ADT中,我进入了Project->Clean。。。这似乎起到了作用。是的,这是资源ID的问题!我试着在之前/之后发布git存储库的一个漂亮的屏幕截图,以便您可以看到R.java文件中的哪些行发生了更改,但我没有足够的信誉点。对不起

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <Button
        android:id="@+id/previous_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/previous_button" />
    <Button 
        android:id="@+id/true_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/true_button"/>
    <Button 
        android:id="@+id/false_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/false_button" />
    <Button 
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"/>
</LinearLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button 
        android:id="@+id/true_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/true_button"/>
    <Button 
        android:id="@+id/false_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/false_button" />
</LinearLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <Button
        android:id="@+id/previous_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/previous_button" />
    <Button 
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"/>
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);
    mQuestionTextView = (TextView)findViewById(R.id.question_text_view);
    mQuestionTextView.setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;

                    updateQuestion();
                }
            });

    mTrueButton = (Button)findViewById(R.id.true_button);
    mTrueButton.setOnClickListener(
            new View.OnClickListener() {
                @Override 
                public void onClick(View v) { 
                    checkAnswer(true);
                }   
            });
    mFalseButton = (Button)findViewById(R.id.false_button);
    mFalseButton.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    checkAnswer(false);
                }
            });

    mNextButton = (Button)findViewById(R.id.next_button);
    mNextButton.setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;

                    updateQuestion();
                }
            });

    mPreviousButton = (Button)findViewById(R.id.previous_button);
    mPreviousButton.setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int length = mQuestionBank.length;
                    mCurrentIndex = (mCurrentIndex + (length-1)) % length;
                    updateQuestion();
                }
            });

    updateQuestion();

}