2011-06-23 8 views
1

私はacdroid用のコードを書くのが初めてで、この問題がありました。 明らかに最初のXMLページ(最初のアクティビティ、つまりnewBill)にアクセスできますが、残りの2つのXMLページ(settleBill.classとProfile.class)にはアクセスできません。 3つのボタンすべてのコードは、ここで見ることができるのとまったく同じです。 3つの独立したJavaファイル - newBill.java、settleBill.java、およびProfile.javaもまったく同じです。私は本当に助けが必要です。ありがとう!(複数のボタン)複数のXMLファイルをAndroidアプリケーション用の1つのメイン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; 
    }*/ 
} 

}

+0

あなたは "私は2 XMLページの残りの部分にアクセスすることはできませんよ" とはどういう意味ですか?アプリケーションがクラッシュしている場合は、詳細をお知らせください(logcat)。 – louiscoquio

+0

マニフェストでこれら2つのアクティビティを定義していますか? – Hitendra

+0

あなたのAndroidManifest.xmlを投稿してください。 – Kenny

答えて

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 
関連する問題