이렇게하면 버튼을 만들고 클릭 리스너를 설정하는 방법입니다. 당신이 시도했습니다처럼
public class MainActivity extends YouTubeFailureRecoveryActivity {
Button amazonButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
amazonButton = (Button) findViewById(R.id.amazonButton);
amazonButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Define what should happen when the button is clicked.
}
});
}
}
또한, 그 방법을 하나의 방법으로 초기화를 넣어 호출 할 수 있습니다
public class MainActivity extends YouTubeFailureRecoveryActivity {
Button amazonButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeViews();
}
private void initializeViews() {
//Make sure you've declared the buttons before you initialize them.
amazonButton = (Button) findViewById(R.id.amazonButton);
amazonButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Define what should happen when the button is clicked.
}
});
// Add more Views initialization here ...
....
}
}
시도'하는 JButton amazonButton = ...'를. 아마존 버튼이 어떤 종류인지 말할 필요가 있습니다. – csmckelvey
이제 'JButton'에 같은 오류가 표시됩니다. – rakeshdas
'JButton' 클래스를 가져 왔습니까? – csmckelvey