android.app.Dialog__showDialogメソッドの推奨に対して[java android]
Posted: 2014年10月21日(火) 14:50
短時間での連投で申し訳ありません。
今回もSB Creativeから発刊されている[基礎からのAndroidプログラミング]からの質問です。
今度はアクティビティ管理のダイアログの部分(書籍ではp244)の部分を作っていたのですが、今度はshowDialogメソッドが非推奨という警告が出ましたので修正したいと思っています。
元のコードでは↓
なのですが、いろいろ調べた結果、DialogFragmentを使用して作ればいいと言う部分までは分かりました。
しかし、サンプルコードの形を保ったまま(サンプルのswitch文の部分)DrawFragmentを実装する方法が分からずご助力いただきたいと思います。
参考書のサンプルコードを新たに推奨される形に書き直したらどれくらい変わってしまうのか知りたいです。
最後にこのコードは課題などではありません。
参考にしたサイト
http://www.jp-z.jp/changelog/2013-05-02-1.html
http://y-anz-m.blogspot.jp/2011/12/andr ... gment.html
http://dev.classmethod.jp/smartphone/an ... gfragment/
http://www115.sakura.ne.jp/~byunbyun/an ... oid12.html
http://developer.android.com/reference/ ... ivity.html
何かこの書籍に載っているコードの大半は非推奨警告出てばかりな気が・・・
今回もSB Creativeから発刊されている[基礎からのAndroidプログラミング]からの質問です。
今度はアクティビティ管理のダイアログの部分(書籍ではp244)の部分を作っていたのですが、今度はshowDialogメソッドが非推奨という警告が出ましたので修正したいと思っています。
元のコードでは↓
package jp.denpa.dialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.app.AlertDialog;
import android.app.Dialog;
public class DialogActivity extends ActionBarActivity implements View.OnClickListener{
static final int DIALOG_HELLO_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.button_dialog).setOnClickListener(this);
}
@Override
protected Dialog onCreateDialog(int id){
Dialog dialog;
switch(id){
case DIALOG_HELLO_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
builder.setMessage(R.string.hello_world);
dialog = builder.create();
break;
default:
dialog = null;
}
return dialog;
}
public void onClick(View v){
// AlertDialog.Builder builder = new AlertDialog.Builder(this);
// builder.setTitle(R.string.app_name);
// builder.setMessage(R.string.hello_world);
// AlertDialog dialog = builder.create();
// dialog.show();
showDialog(DIALOG_HELLO_ID); //高APIでは非推奨という警告を発する
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dialog, 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);
}
}
しかし、サンプルコードの形を保ったまま(サンプルのswitch文の部分)DrawFragmentを実装する方法が分からずご助力いただきたいと思います。
参考書のサンプルコードを新たに推奨される形に書き直したらどれくらい変わってしまうのか知りたいです。
最後にこのコードは課題などではありません。
参考にしたサイト
http://www.jp-z.jp/changelog/2013-05-02-1.html
http://y-anz-m.blogspot.jp/2011/12/andr ... gment.html
http://dev.classmethod.jp/smartphone/an ... gfragment/
http://www115.sakura.ne.jp/~byunbyun/an ... oid12.html
http://developer.android.com/reference/ ... ivity.html
何かこの書籍に載っているコードの大半は非推奨警告出てばかりな気が・・・