i have a problem trying to show an image in an AlertDialog with a ListView, here the code:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ListView modeList = new ListView(this);
stringArray = new String[1];
**stringArray[0] = new String(getString( R.string.facebook),getImg( R.drawable.icon ));**
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
modeList.setAdapter(modeAdapter);
builder.setTitle("Share");
builder.setIcon(R.drawable.icon);
builder.setItems(stringArray, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
//Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();
and
private Drawable getImg( int res )
{
Drawable img = getResources().getDrawable( res );
img.setBounds( 0, 0, 48, 48 );
return img;
}
and the error says me: “The constructor String(String,Drawable) is undefined”
I would like, to show an image custom and a text in an AlertDialog with a ListView. Thanks.
A
Stringis only aString. You cannot put aDrawablein the constructur. And as you use the getString method, you dont need the constructor anyway: