...이 그 초보자 질문 중 하나가 될 것입니다 100 % 확신하지만, 여기 간다 앱에서 사용할 수있는 메소드는 무엇입니까?
내가 한 활동 방법을 작성하고에서 액세스 할 수있는 방법이 있나요 다른 사람? 는예 : 내 응용 프로그램에서 여섯 명하는 행동이이 , 그 자체 menu.xml 각 각에 대해 사용할 수있는 옵션이 다를 수해야하기 때문에, 그림과 같이 나는이 메뉴를 설정 & 메뉴 아이템이 있습니다
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.calculator_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
//Handle item selection
switch (item.getItemId()) {
case R.id.menuItem_calculator_Help:
helpDialogGo();
return true;
case R.id.menuItem_calculator_Settings:
//settingsActivityGo();
return true;
case R.id.menuItem_calculator_Share:
shareGo();
return true;
case android.R.id.home:
// app icon in Action Bar clicked; go home
Intent uptohome = new Intent(this, Main.class);
uptohome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(uptohome);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
다음은 이러한 방법 중 하나의 예입니다
private void helpDialogGo() {
Toast.makeText(this, "help", Toast.LENGTH_LONG).show();
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Sorry, no help has been written since this application is still in development. This is a prerelease version.")
.setCancelable(false)
.setPositiveButton("Cool", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
dialog.cancel();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Pixel Help");
// Icon for AlertDialog
alert.setIcon(R.drawable.question);
alert.show();
}
그래서 피하기 위해로서, 모든 활동에서 공유이 사용자 정의 방법이 있고 버튼이 그들 각각에 눌렀을 때 실행하는 방법은 무엇입니까 거대한 amoun를 가지고있는 t의 코드가 내 앱에서 복제 되었습니까?
그렇다면 내가 쳤을 수있는 움푹 들어간 곳이 있습니까? (일부 메뉴 항목은 대화 상자를 가져오고 다른 사용자는 새로운 활동으로 사용자를 이동시킵니다.)
이것은 실제로 이렇게하는 일반적인 방법입니다. 그리고 안드로이드에만 국한된 것은 아니지만 클래스 디자인에 대한 모범 사례와 더 관련이 있습니다. – omermuhammed
제가 시작하기 전에 좀 더 자세히 설명해 주실 수 있습니까? – rabbitt
@omermuhammed가 이에 동의합니다. rabs83 @ – GSree