Guian wrote:
> I've created a custom view via .xml file,
> and I wanted to add it as a a contentView to an alert Dialog usinf a
> dialogBuilder:
> 
> 
> AlertDialog.Builder builder = new AlertDialog.Builder(this);
>         builder.setNeutralButton( _Res.getString(R.string.close), new
> DialogInterface.OnClickListener(){
>                       public void onClick(DialogInterface dialog, int which) {
>                               myDial.dismiss();
>                       }
>         });
>         builder.setCancelable(true);
>               builder.setIcon(R.drawable.my_icon);
>       builder.setTitle(R.string.title);
> 
>       builder.setView(   HERE I SHOULD USE myCustomLayout   );
>       builder.create();
> 
> TextView text = (TextView) myCustomLayout.findViewById(R.id.goTotext);
> text.setText("toto");
> ... etc...
> 
> builder.show();
> 
> 
> 
> The problem is...  I can't get my view from my custom layout...
> I only have an  id (int)...
> 
> I tried Resource.getLayout(int) => it returns an xmlParser... not very
> usefull ...
> 
> finally the solution I comes up is so disgusting ( it worked but ...
> let's have a look)
> 
> AlertDialog.Builder builder = new AlertDialog.Builder(this);
>         builder.setNeutralButton( _Res.getString(R.string.close), new
> DialogInterface.OnClickListener(){
>                       public void onClick(DialogInterface dialog, int which) {
>                               myDial.dismiss();
>                       }
>         });
>         builder.setCancelable(true);
>               builder.setIcon(R.drawable.my_icon);
>       builder.setTitle(R.string.title);
> 
>       Dialog tmpDial = new Dialog(this); // create a tmp dialog ...
>       tmpDial.setContentView(R.layout.settings_dialog); // put my
> custom layout as the content view of the tmp Dialog
> 
>       View tmp  = (View)tmpDial.findViewById(R.id.setting_dial_lay); //
> get my layout as a View ...
>       tmpDial.setContentView(new View(this)); // set a new content
> View to the tmp dial to remove my view from his parent... (so sad
> isn't it ?)
> 
>       builder.setView(tmp); / here I have my view ready to be used....
> but isn't it really disgusting ... ??
>       builder.create();
> 
> 
> 
> ... so guys,  how can I do that easily without using such a disgusting
> way... ?

Use LayoutInflater, obtained via getLayoutInflater() from your Activity.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 1.0 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to