AlertDialogでのURL画像表示

このQ&Aのポイント
  • アンドロイド開発で「AlertDialog.Builder」を使用し、URL画像を表示するコーディングを試みていますが、エラーが出力されます。
  • 解決できずに1週間ほど経過しています。
  • ヒントをいただけると助かります。
回答を見る
  • ベストアンサー

AlertDialogでのURL画像表示

現在、アンドロイド開発で「AlertDialog.Builder」を使用し、URL画像を表示するコーディングを試みております。 しかし、「R.id.image」の部分をURL画像で指定するとエラーが出力してしまいます。 LayoutInflater inflater = LayoutInflater.from(AlerDialog.this); View layout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) findViewById(R.id.layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(country_name + "\n" + sex + "\n" + receipt_end_date); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(R.drawable.icon); new AlertDialog.Builder(AlerDialog.this) .setTitle(title) .setCancelable(false) .setPositiveButton("Look!", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //webview.loadUrl(URL_ESTIMATE_USER_HISTORY); //BaseActivity.this.finish(); } }) .setNegativeButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .setView(layout) .show(); 解決できずに1週間ほどすぎ、現在に至っております。 何かヒントを頂ければ有り難いです。 宜しくお願いします。

  • uekyo
  • お礼率80% (8/10)
  • Java
  • 回答数1
  • ありがとう数4

質問者が選んだベストアンサー

  • ベストアンサー
  • XBG
  • ベストアンサー率60% (493/820)
回答No.1

URL画像とはどのようなものでしょうか?それがはっきりしないと明確な回答ができません。 仮にインターネット上の画像を求めると仮定して回答します。(×「URL画像」○「画像URL」) >しかし、「R.id.image」の部分をURL画像で指定するとエラーが出力してしまいます。 >ImageView image = (ImageView) layout.findViewById(R.id.image); そもそもこのR.id.imageが何を指すかご存じでしょうか。 この行はいずれかのレイアウトに存在するimageというIDのImageViewオブジェクトに対して、変数にコントロールを代入するという指定です。 表示する画像を変更するものではありません。 変更を行うのは直後の行です >image.setImageResource(R.drawable.icon); ただし、これはプロジェクト内のリソースしか指定できないので、インターネット上の画像を表示するにはHTTPでファイルを取得し、それをBitmapに取得してから、別のメゾッドを使用する必要があります。

uekyo
質問者

お礼

ご返答おそくなってしまい、すみません。 上記、非常にわかりやすいアドバイスありがとうございます。 BitMapに変換して実現するのですね。 現在、HTMLコンテンツをダイアログ内に表示することで急場をしのいでおりますが時期バージョンを今月更新するので、その際にBitmapでの表示を実現してみます。 ありがとうございました。

関連するQ&A

  • Javaの質問です(引数の中でメソッド定義?)

    お世話になります。 現在、Javaについて勉強しておりまして一つ不明な点があり投稿させていただきました。 まずはソースをご覧ください。 ---------------------------------------------------------------------------------------------- button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Main.this, Editor.class); TextView textView = (TextView)findViewById(R.id.TextView01); CharSequence text = textView.getText(); intent.putExtra("TEXT", text + "000"); startActivityForResult(intent, SHOW_EDITOR); } }); ---------------------------------------------------------------------------------------------- 上記はサンプルプログラムから一部抜粋したものですが button.setOnClickListenerの引数でnew演算子を使用しており、 尚かつonClickメソッドをオーバーライドして定義しています。 C++開発経験者の私としては非常に見づらいのですが、こんな書き方って結構使うんでしょうか? これがイマイチ理解できていません。 この書き方をネットで探しても見つからなかったため、こちらでご質問させていただきました。 どなたかご教授願います。

  • 二つのコードを繋げたい

    eclipseでandroidプログラミングをしている超初心者です。 いろいろ試しましたがうまくいかないので力を貸してください。 コード1 final String TAG = "DialogTest"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ((Button)findViewById(R.id.button1)) .setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this) .setTitle("Hello, AlertDialog!") .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .show(); } }); } } コード2 EditText mEditText_number = null; LinearLayout mLinearLayout_no_button = null; Button mButton_dial = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLinearLayout_no_button = new LinearLayout(this); mEditText_number = new EditText(this); mEditText_number.setText("117"); mLinearLayout_no_button.addView(mEditText_number); mButton_dial = new Button(this); mButton_dial.setText("電話をかける"); mLinearLayout_no_button.addView(mButton_dial); mButton_dial.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { performDial(); } }); setContentView(mLinearLayout_no_button); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_CALL) { performDial(); return true; } return false; } public void performDial(){ if(mEditText_number!=null){ try { startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mEditText_number.getText()))); } catch (Exception e) { e.printStackTrace(); } } } } AlertDialogを表示するコード1で”YES”を押したらコード2を使って電話がかかるようにしたいです。 回答よろしくお願いします。

  • android Javaの画像表示について

    ImageView image1 = new ImageView(this); image1.setScaleType(ImageView.ScaleType.CENTER); image1.setImageDrawable(getResources().getDrawable(R.drawable.gazou)); setContentView(image1); で画像を表示させたりしているのですが画像パスにString型の引数を使う方法が知りたいです。 また scaletypeだと他のレイアウトが消えたりするので他にいい方法はないのですか?

    • ベストアンサー
    • Java
  • android.R.id.text1はどこにある

    androidアプリ開発 を読みながら、作業しています。 ( 184ページ ) サンプルのコード SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this, g_list, android.R.layout.simple_expandable_list_item_1, new String[] { "group_title"}, new int[]{android.R.id.text1 }, c_list, android.R.layout.simple_expandable_list_item_2, new String[] {"child_title", "child_text" }, new int[] { android.R.id.text1, android.R.id.text2 } ); elv.setAdapter(adapter); elv.setOnChildClickListener( new OnChildClickListener() { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { TextView txt = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text1); Toast.makeText(AddrListShowActivity.this, txt.getText(), Toast.LENGTH_LONG).show(); return false; } } は、動くのですが、欲張って SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this, g_list, android.R.layout.simple_expandable_list_item_1, new String[] { "group_title"}, new int[]{android.R.id.text1 }, c_list, android.R.layout.simple_expandable_list_item_2, new String[] {"child_title", "child_text" }, new int[] { android.R.id.text2, android.R.id.text3 } ); elv.setAdapter(adapter); elv.setOnChildClickListener( new OnChildClickListener() { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { TextView txt = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text1); Toast.makeText(AddrListShowActivity.this, txt.getText(), Toast.LENGTH_LONG).show(); TextView txt2 = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text2); Toast.makeText(AddrListShowActivity.this, txt2.getText(), Toast.LENGTH_LONG).show(); TextView txt3 = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text3); Toast.makeText(AddrListShowActivity.this, txt3.getText(), Toast.LENGTH_LONG).show(); return false; } } とすると、android.R.id.text3  が原因で動きません。 そもそも、android.R.id.text1 の  text1 は何処にあるのでしょうか。 アドバイスよろしくお願いします。  

  • androidプログラミングについての質問

    このプログラムについて質問したいのですが public class InOutTest extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public TextView txtResult; public TextView txtjudge; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから // ラベル txtInfo = new TextView(this); txtInfo.setText("check spell same or not:"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setTextSize(30f); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { String strInch = ""; if (edtText==txtInfo) strInch = "typed as same"; txtResult.setText(strInch); } }); } } txtResultに文章を引き渡して表示させたいのですが やり方が分かりません お時間のある方でいいので どなたかよろしければ教えてください

  • このプログラムについて質問したいのですが

    public class InOutTest extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public TextView txtResult; public TextView txtjudge; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから // ラベル txtInfo = new TextView(this); txtInfo.setText("check spell same or not:"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setTextSize(30f); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { String strInch = ""; if (edtText==txtInfo) strInch = "typed as same"; txtResult.setText(strInch); } }); } } txtResultに文章を引き渡して表示させたいのですが やり方が分かりません お時間のある方でいいので どなたかよろしければ教えてください

    • ベストアンサー
    • Java
  • androidでアプリを作ろうとしてるのですが

    package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class InOutTest extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public TextView txtResult; public TextView txtjudge; public String strInch; public String gettext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから // ラベル txtInfo = new TextView(this); txtInfo.setText("check"); strInch = ("check"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setText("check"); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { gettext = edtText.toString(); if (strInch==gettext){ txtjudge.setText("ok"); } }; }); }} 上のプログラムで strInchに入ってるデータとgettextで取得した文章を比較して同じなら txtjudgeにOKと引き渡して表示させたいのですがうまく動きません 何方かどうぞよろしくお願い致します

    • ベストアンサー
    • Java
  • Androidでこのエラーを解決したいです

    どなたかご教授お願いします package com.example.kusogame; import宣言省略 public class TypingKusoGame extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public Button createtext; public TextView txtResult; public TextView Title; public TextView txtjudge; public String strInch; public String gettext; public String test = "check"; public ImageView judgecat; public int idx = 0; private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; public int createParam; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから //タイトル Title = new TextView(this); Title.setText("Let's Training!"); Title.setTypeface(Typeface.DEFAULT_BOLD); Title.setTextScaleX(1.5f); Title.setTextColor(Color.rgb(255,0,0)); layout.addView(Title); // ラベル txtInfo = new TextView(this); txtInfo.setText("check"); txtInfo.setTextScaleX(1.5f); strInch = ("check"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setText("check"); layout.addView(txtjudge); //結果表示用猫ラベル judgecat = new ImageView(this); judgecat.setImageResource(R.drawable.failed); LinearLayout.addView(judgecat,LayoutParams(WC)); ~~~~~~~~~~~~~~このエラーが解決できません メソッドLayoutParam(int)は 型TypingKusoGameで未定義です //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ pub

    • ベストアンサー
    • Java
  • 【Android開発】ボタンのテキスト表示

    Android初心者です。現在画面遷移先の画面に配列で設定した質問文、選択肢を表示するアプリを制作しています。質問文はTextView、選択肢は2つのButtonにテキストとして表示する。画面遷移した後にsetQuestion()、setChoiceを呼び出したいんですが実機で試したところ、画面遷移した後に「問題が発生しため、(アプリ名)を終了します」とポップアップが出て、アプリが落ちます。 この2つのメソッドをonCreateに入れるのは間違なのでしょうか?どうすればうまくいきますか?初心者なのでうまく書けてないかも知れません。 よろしくお願いします。 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sub); setChoice(); setQuestion();  } int number = 0; //質問番号 //選択肢 Button button1; Button button2; Button button3; Button button4; //質問文を配列に格納 static String question[] = { "質問文1", "質問文2", }; //選択肢 static String choice[][] = { {"1番", "2番", "3番", "4番"}, {"1番", "2番", "3番", "4番"}, }; //問題の回答 static String answer[] = { "2番", "4番" }; //出力 //質問文を表示 public void setQuestion() { String setQuestion = question[number]; // TextView question = (TextView) findViewById(R.id.Question); question.setText(setQuestion); } //選択肢の表示 public void setChoice() { TextView button1 = (Button) findViewById(R.id.button1); TextView button2 = (Button) findViewById(R.id.button2); button1.setText(choice[number][0]); button2.setText(choice[number][1]); } xml <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Question" android:id="@+id/Question" android:textSize="40dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="81dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:textSize="30dp" android:onClick="choiceClick" android:layout_above="@+id/button2" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:textSize="30dp" android:onClick="choiceClick" android:layout_alignParentBottom="true" android:layout_alignLeft="@+id/button1" android:layout_alignStart="@+id/button1" />

  • クリックして画像を変え、一定時間経過後もとに戻す

    androidアプリを作成している初心者です。 画像をクリックすると画像が変わるようになるようにしたいと思ってます。 画像を変えるところまではできたのですが、 一定時間経過後にもとに戻すにはどうしたらいいかがわかりません。 以下、ソースコード。 public class MainActivity extends Activity { ImageView iv; Bitmap bmp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); ll.setGravity(Gravity.CENTER); setContentView(ll); //画像表示 iv = new ImageView(this); bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ikari); iv.setImageBitmap(bmp); ll.addView(iv); //画像をクリックした時に関数を呼び出す iv.setOnClickListener(new img_ac()); } //画像を変える class img_ac implements OnClickListener { public void onClick(View v) { ImageView tmp = (ImageView) v; tmp.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } } } 一定時間経過後に元の画像に戻すには、どのようにしたら良いのでしょうか。

    • ベストアンサー
    • Java