MainActivity
에이 코드에 두 번째 단추를 추가하려면 어떻게합니까? 아마 내가 여기 바보 같은 짓을하고 있다는 것을 알고 있지만 두 번째 버튼에 대한 코드를 다른 활동에 연결하는 위치를 모르겠습니다. 내 첫 번째 버튼은 정상적으로 작동하며 두 번째 버튼을 어떻게 처리해야할지 모릅니다.MainActivity에 두 번째 단추 코드를 추가하는 방법
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonabout = (Button)findViewById(R.id.button3);
buttonabout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),MainActivity2.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
에서 지금
는 두 번째 버튼의 ID로'버튼 단추 2를 = ..' 작성하여 첫 번째 단추로 같은 방법으로 추가합니다. – BluesSolo