【问题标题】:How to create a new screen from the main screen?如何从主屏幕创建新屏幕?
【发布时间】:2011-07-10 03:16:28
【问题描述】:

当我点击“报告” Button 时,我想创建一个新屏幕。在那个新屏幕上,我想显示项目列表。 我试过了,但失败了。我创建了一个新的Activity 类和一个新的xml 文件。

公共类报告扩展 MainActivity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.report);

    ListView mWeek = (ListView) findViewById(R.id.week); 
    ListView mMonth = (ListView) findViewById(R.id.month); 
    ListView mYear = (ListView) findViewById(R.id.year); 
}

MainActivity.java:

public void createReport(View v){
    Intent intent = new Intent(this, Report.class);
    startActivity(intent);
}   

有没有其他方法可以创建新的screen,请提供任何其他方法来创建它。

【问题讨论】:

  • 你是怎么失败的。错误是什么?

标签: android android-layout layout screen android-button


【解决方案1】:

为您要显示的内容创建新的 menuclass.xml ..... 给他们身份证。

View v1= findViewById(R.id.subid);
b1= (Button)v1;

b1.setOnClickListener(new OnClickListener(){

    public void onClick(View v)
    {
        Intent intent=new Intent(Main.this,MenuCalls.class);
        startActivity(intent);
    }
}

并在 write 中创建新的 MenuCalls 类

public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menucalls);

    ListView mWeek = (ListView) findViewById(R.id.week); 
    ListView mMonth = (ListView) findViewById(R.id.month); 
    ListView mYear = (ListView) findViewById(R.id.year); 

}

【讨论】:

    【解决方案2】:

    您可以使用片段。每个片段都有一个视图,通过片段事务您可以在单个活动中管理多个视图。

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 2012-08-19
      • 2011-10-14
      相关资源
      最近更新 更多