0

たとえば、エラーが発生した場合は、間違ったアイコンや正しいアイコンなど、この動作に適したアイコンが表示されます。

if(condition true)
{
  //here i need set right icon
}
if(condition false)
 {
 //here i need set wrong icon
AlertDialog ad = new AlertDialog.Builder(MainActivity.this).create();
ad.seticon();//how to set for different behavior
4

2 に答える 2

1

false/wrong (デフォルト値として) のドローアブル ID を保持するようにを作成し、intそれが true/right の場合は、何resIdを指すかを変更します。デフォルトのアイコンが必要ない場合は、resId0 に設定します。次に、AlertDialog を作成した後にアイコンを設定します。

int resId = R.drawable.false;

if(condition == true)
{
  resId = R.drawable.true;
}

 //here i need set wrong icon
AlertDialog ad = new AlertDialog.Builder(MainActivity.this).create();
ad.setIcon(resId);//how to set for different behavior

もちろん、フォルダーtruefalse写真があることを確認してください。res/drawable

于 2013-01-31T18:31:15.443 に答える
0

画像を設定resource idcorrect/wrong、メソッドを呼び出して、適切なアイコンでダイアログを表示します。

int res_id=0;

  if(condition true)
  {
       res_id = R.drawable.correct;
       myDialog(res_id);
  }

 if(condition false)
  {

        res_id = R.drawable.wrong;
        myDialog(res_id);
   }

  void myDialog(int resId){

        AlertDialog ad = new AlertDialog.Builder(MainActivity.this).create();
        ad.setIcon(resId);

   }
于 2013-01-31T19:05:12.850 に答える