アラート ダイアログ内で GridView を作成することは可能ですか?
現時点では、単語検索があり、解決策 (完了した単語検索) をポップアップ ダイアログに表示したいので、ユーザーはパズルと回答をすばやく切り替えることができます。
こんな感じで実装してみました
AlertDialog.Builder aBuilder = new AlertDialog.Builder(this);
// set title
aBuilder.setTitle("The solution");
GridView g = null ;
final ArrayAdapter<String> Wordadapter = new ArrayAdapter<String>(getApplicationContext(),
R.layout.wordsstyle, WordsToFind);
g.setNumColumns(Length);
g.setAdapter(Wordadapter);
aBuilder.setView(g);
aBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
}
});
ただし、クラッシュするだけです
私はこれをログキャットで取得しています
04-24 21:17:48.472: E/AndroidRuntime(826): FATAL EXCEPTION: main
04-24 21:17:48.472: E/AndroidRuntime(826): java.lang.IllegalStateException: Could not execute method of the activity
04-24 21:17:48.472: E/AndroidRuntime(826): at android.view.View$1.onClick(View.java:3591)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.view.View.performClick(View.java:4084)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.view.View$PerformClick.run(View.java:16966)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.os.Handler.handleCallback(Handler.java:615)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.os.Handler.dispatchMessage(Handler.java:92)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.os.Looper.loop(Looper.java:137)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-24 21:17:48.472: E/AndroidRuntime(826): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:17:48.472: E/AndroidRuntime(826): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 21:17:48.472: E/AndroidRuntime(826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-24 21:17:48.472: E/AndroidRuntime(826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-24 21:17:48.472: E/AndroidRuntime(826): at dalvik.system.NativeStart.main(Native Method)
04-24 21:17:48.472: E/AndroidRuntime(826): Caused by: java.lang.reflect.InvocationTargetException
04-24 21:17:48.472: E/AndroidRuntime(826): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:17:48.472: E/AndroidRuntime(826): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 21:17:48.472: E/AndroidRuntime(826): at android.view.View$1.onClick(View.java:3586)
04-24 21:17:48.472: E/AndroidRuntime(826): ... 11 more
04-24 21:17:48.472: E/AndroidRuntime(826): Caused by: java.lang.NullPointerException
04-24 21:17:48.472: E/AndroidRuntime(826): at com.example.angrywordsearch.Puzzle_Activity.GridPopup(Puzzle_Activity.java:726)
04-24 21:17:48.472: E/AndroidRuntime(826): at com.example.angrywordsearch.Puzzle_Activity.ViewSolution_Click(Puzzle_Activity.java:686)
04-24 21:17:48.472: E/AndroidRuntime(826): ... 14 more