Dialog problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Dialog problem

Postby CTAPbIu_MABP » Tue Sep 15, 2009 1:56 pm

Hi. I have been reading forum over the past few days and find many answers for my questions.
But still cant find a solution for one little problem

i have some activity and 3 methods

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class MyActivity extends Activity {
  3.  
  4.  
  5.  
  6.     private static final int DIALOG = 1;
  7.  
  8.  
  9.  
  10.     @Override
  11.  
  12.     public void onCreate(Bundle savedInstanceState) {
  13.  
  14.         super.onCreate(savedInstanceState);
  15.  
  16.         setContentView(R.layout.my_layout);
  17.  
  18.  
  19.  
  20.         Button send = (Button) findViewById(R.id.my_dialog_btn);
  21.  
  22.         send.setOnClickListener(new View.OnClickListener() {
  23.  
  24.             public void onClick(View v) {
  25.  
  26.                 showDialog(DIALOG);
  27.  
  28.             }
  29.  
  30.         });
  31.  
  32.  
  33.  
  34.     }
  35.  
  36.  
  37.  
  38.     @Override
  39.  
  40.     protected Dialog onCreateDialog(int id) {
  41.  
  42.         super.onCreateDialog(id);
  43.  
  44.         switch (id) {
  45.  
  46.             case DIALOG:
  47.  
  48.                 LayoutInflater factory = LayoutInflater.from(this);
  49.  
  50.                 View sendResponseView = factory.inflate(R.layout.my_dialog_layout, null);
  51.  
  52.  
  53.  
  54.                 return new AlertDialog.Builder(MyActivity.this)
  55.  
  56.                         .setIcon(R.drawable.alert_dialog_icon)
  57.  
  58.                         .setView(sendResponseView)
  59.  
  60.                         .setTitle(R.string.my_dialog_title)
  61.  
  62.                         .setPositiveButton(R.string.my_dialog_ok, new DialogInterface.OnClickListener() {
  63.  
  64.                             public void onClick(DialogInterface dialog, int whichButton) {
  65.  
  66.  
  67.  
  68.                             }
  69.  
  70.                         })
  71.  
  72.                         .setNegativeButton(R.string.go_to_main, new DialogInterface.OnClickListener() {
  73.  
  74.                             public void onClick(DialogInterface dialog, int whichButton) {
  75.  
  76.  
  77.  
  78.                             }
  79.  
  80.                         })
  81.  
  82.                         .create();
  83.  
  84.             default:
  85.  
  86.                 return null;
  87.  
  88.         }
  89.  
  90.        
  91.  
  92.     }
  93.  
  94.  
  95.  
  96.     @Override
  97.  
  98.     protected void onPrepareDialog(int id, Dialog dialog) {
  99.  
  100.         super.onPrepareDialog(id, dialog);
  101.  
  102.         switch (id) {
  103.  
  104.             case DIALOG:
  105.  
  106.                   AlertDialog myDialog = (AlertDialog)dialog;
  107.  
  108.                   myDialog.setTitle(R.string.my_another_dialog_title)
  109.  
  110.                   break;
  111.  
  112.             default:
  113.  
  114.                   break;
  115.  
  116.         }
  117.  
  118.        
  119.  
  120.     }
  121.  
  122. }
  123.  
  124.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


when i set Dialog title in onCreateDialog everything is ok. it works.
but when i reset it in onPrepareDialog it doesnt work.

what im doing wrong?
CTAPbIu_MABP
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 15, 2009 1:32 pm

Top

Postby CTAPbIu_MABP » Tue Sep 15, 2009 2:30 pm

sorry in my example it works correct but in application it doesnt :(
CTAPbIu_MABP
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 15, 2009 1:32 pm

Postby qlimax » Tue Sep 15, 2009 3:09 pm

are you missing " ; " at the end of setTitle() call ?

sorry if is'n that :?
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby CTAPbIu_MABP » Tue Sep 15, 2009 3:12 pm

qlimax this is just mistyping :)

the problem i think is in onCreateDialog
i remove setTitle from onCreateDialog at all and onPrepareDialog cant set it
CTAPbIu_MABP
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 15, 2009 1:32 pm

Postby qlimax » Tue Sep 15, 2009 3:46 pm

when you try to set title in onPrepareDialog, does the debugger give you some exception, or the title will just not set?
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby CTAPbIu_MABP » Tue Sep 15, 2009 3:50 pm

no exception ;)

i think dialog layout was cached without title and thats why i cant set it
sorry but now i cant check this theory
CTAPbIu_MABP
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 15, 2009 1:32 pm

Top

Postby shaobin0604 » Fri Dec 11, 2009 7:02 am

CTAPbIu_MABP wrote:no exception ;)

i think dialog layout was cached without title and thats why i cant set it
sorry but now i cant check this theory


hi,

if you want to change the title later in onPreparedDialog, you should call setTitle in onCreateDialog first.
shaobin0604
Freshman
Freshman
 
Posts: 3
Joined: Sat Nov 14, 2009 3:51 am

Postby CTAPbIu_MABP » Fri Dec 11, 2009 9:55 am

shaobin0604, hi!

this was it ;) thx!
CTAPbIu_MABP
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 15, 2009 1:32 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests