有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java根据条件显示不同的布局

在我的例子中,我有两个布局,但我已经检查了main活动的oncreate,如果创建了文件,那么打开indexpage,activity_indexpage2。xml,但我无法打印此结果以检查错误

protected void onCreate(Bundle savedInstanceState) {
    try {
        contentfile = read();

    } catch (IOException e) {
        e.printStackTrace();
    }
    if(contentfile!=null
    ){
        Intent intent = new Intent(MainActivity.this, indexpage.class);
        setContentView(R.layout.activity_indexpage2);
        startActivity(intent);
    }
    `super.onCreate(savedInstanceState);`
     public String read() throws IOException {

    FileInputStream input = this.openFileInput(File_NAME);
    byte[] temp = new byte[1024];
    StringBuffer stringBuffer = new StringBuffer("");
    int len = 0;
    while ((len = input.read(temp)) > 0) {
        stringBuffer.append(new String(temp, 0, len));
    }

    input.close();
    return stringBuffer.toString();
}

共 (0) 个答案