(多个按钮)如何将多个XML文件链接到Android应用程序的1个主Java页面?

时间:2011-06-23 17:34:29

标签: android android-layout

我是新手为acdroid编写代码并遇到了这个问题。 显然我可以访问第一个xml页面(第一个Activity,即newBill),但我无法访问其余的2个xml页面(settleBill.class和Profile.class)。所有3个按钮的代码与您在此处看到的完全相同。 3个独立的java文件--newBill.java,settleBill.java和Profile.java也完全相同。我真的需要帮助。谢谢!

public class SplitB extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   // setContentView(R.layout.settlement);

    Button newBill = (Button) findViewById(R.id.newbill);
    newBill.setOnClickListener(this);

    Button settleBill =(Button) findViewById(R.id.settlebill);
    settleBill.setOnClickListener(this);

    Button myProfile = (Button) findViewById(R.id.profile);
    myProfile.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    if(v.getId() == R.id.newbill)
    {
        startActivity(new Intent(SplitB.this,newBill.class));
    }
    else if(v.getId() == R.id.settlebill)
    {
        startActivity(new Intent(SplitB.this,settleBill.class));
    }
    else
    {
        startActivity(new Intent(SplitB.this,Profile.class));

    }
    /*switch(v.getId())
    {
        case R.id.newbill: 
            startActivity(new Intent(SplitB.this,newBill.class));
            break;

        case R.id.settlebill:
            startActivity(new Intent(SplitB.this,settleBill.class));
            break;

        case R.id.profile:
            startActivity(new Intent(SplitB.this,settleBill.class));
            break;
    }*/
}

}

1 个答案:

答案 0 :(得分:1)

LayoutInflater in=(LayoutInflater)getLayoutInflater(savedInstanceState);
      View  v=in.inflate(R.layout.2.xml/3.xml, null);
then
    Button b=(Button)v.findviewByid(r.id.button1); we acess