java - 无法让我的 if 语句发挥作用?

标签 java android xml

我知道这一定很简单。但对于我的一生,我不知道为什么我不能把这件事做好。

好的,所以我想从 ListView 页面进入(明白了),然后单击一个开关使其进入下一页(也明白了。)然后我想要一个 int 来告诉我我在表单中的哪个位置最后一页(可能有效?)现在我无法让 If Else 语句在该页面中工作。

public class NightmareParts extends Activity
{
    public int current_AN_Number = NightmareList.AN_position_num;
    private TextView edit_title;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.part_layout);

        // isn't working here. Why?
        // test_edit = (TextView)findViewById(R.id.directions_tv);        
        // test_edit.setText(R.string.directions_text_two);                 
        // works without this being in here. 

        setDoneButtonListener();
    }

    //Set up the Done button to initialize intent and finish
    private void setDoneButtonListener()
    {
        Button doneButton = (Button) findViewById(R.id.back_button);
        doneButton.setOnClickListener (new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                finish();
            }
        });
    }

    private void editTitle()
    {
        if (current_AN_Number = 1)
        {
            edit_title = (TextView)findViewById(R.id.part_title);           
            edit_title.setText(R.string.AN_title_1);                        
        }           
    }
}

current_AN_number 来自最后一页。

最佳答案

您的 if 语句不正确:

if (current_AN_Number = 1)

当您想将赋值运算符与 == 运算符进行比较时,您已经使用了赋值运算符:

if (current_AN_Number == 1)

关于java - 无法让我的 if 语句发挥作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20436170/

相关文章:

java - JDBC 程序调用具有复杂输入和输出的存储过程

java - subList() 与其他类似的 Collections 方法有不同的行为,一旦 subList 被改变

java - Intellij Idea- Gradle : Execution failed for task ':compileJava'

android - 如果将 PendingIntent 上的标志设置为 0 会发生什么情况?

java - 构造函数中的同步块(synchronized block)

android - ScrollView 不使用 ConstraintLayout 和指南滚动

xml - 如何在 XHTML 中使用 HTML5 数据属性?

java - 无法使用 findFragmentById 访问我的 fragment

xml - 基于 XSD 的自动完成 - 我还可以显示有用的评论吗?

Android 使用游标适配器在 ListView 中保存复选框状态