开发者

(Multiple buttons) How to link multiple XML files to 1 main Java page for Android apps?

开发者 https://www.devze.com 2023-03-15 12:18 出处:网络
I am new to writing code for acdroid and had this problem. Apparently i can access the first xml page (first Activity i.e. newBill) but i am not able to access the rest of the 2 xml pages (settleBill.

I am new to writing code for acdroid and had this problem. Apparently i can access the first xml page (first Activity i.e. newBill) but i am not able to access the rest of the 2 xml pages (settleBill.class and Profile.class). The code for all 3 buttons is exactly the same as u can see here. The 3 independent java files - newBill.java, settleBill.java and Profile.java are also exactly the same. I really need help. Thanks!

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(Spl开发者_如何学运维itB.this,settleBill.class));
            break;
    }*/
}

}


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
0

精彩评论

暂无评论...
验证码 换一张
取 消