Sunday, February 27, 2011

Re: [android-developers] EditText behaving weirdly

Ok. This is going to be pretty long. Posted below is the onCreateDialog and onPrepareDialog.

Another, possible related issue is that when the screen rotates to landscape mode, the dialog box is opened again for reasons unknown.



 @Override
    protected Dialog onCreateDialog(int id) {
       
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        Context mContext = getApplicationContext();
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
        final View layout;
       
       
        switch (id){       
            //created when the user clicks on a child item
            case  EDITITEM_DIALOG_ID:
                           
                //build custom dialog to update selected data
                layout = inflater.inflate(R.layout.budget_dialog_edit_child,(ViewGroup) findViewById(R.id.BudgetMain_llDialogEdit));
           
                builder.setTitle("Edit\\Delete:\n" + BudgetItem);
                builder.setMessage("Edit price or delete if no longer required");
                builder.setView(layout);
     
               
                builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int whichButton) {
                                                       
                                                        final EditText edAmount = (EditText)layout.findViewById(R.id.BudgetMainEdit_edAmount);
                                                   
                                                       
                                                        if ( edAmount.getText().toString().equals("") )
                                                            mDbBudget.updateAmount(BudgetRowID, 0.00);
                                                        else
                                                            mDbBudget.updateAmount(BudgetRowID, Double.valueOf(edAmount.getText().toString()));
                                                       
                                                        mAdapterCursor.requery();
                                                        setBudgetUsed();
                                                    }
                });
                   
                builder.setNegativeButton("Delete",new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog, int whichButton) {
                                                            dialog.cancel();
                                                           
                                                           
                                                            if (mDbBudget.deleteItem(BudgetRowID)) {
                                                                mAdapterCursor.requery();
                                                                setBudgetUsed();
                                                            }                                                               
                                                   
                                                        }
                });
               
                 builder.setNeutralButton("Cancel",  new DialogInterface.OnClickListener() {
                                                         public void onClick(DialogInterface dialog, int whichButton) {
                                                             dialog.dismiss();
               
                                                         }
                 });
   
               
                return builder.show();

            case EDITTOTAL_DIALOG_ID:
               
                layout = inflater.inflate(R.layout.budget_dialog_edit_total,(ViewGroup) findViewById(R.id.Budget_Dialog_Edit_Total_llTotal));
           
                builder.setTitle("Edit Total Budget");
                builder.setMessage("Edit the wedding's total budget amount");
                builder.setView(layout);
                builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                                                      public void onClick(DialogInterface dialog, int whichButton) {
                                                       
                                                        final EditText edAmount = (EditText)layout.findViewById(R.id.Budget_Dialog_Edit_Total_edTotal);
                                                        mDbSettings.open();
                                                       
                                                        if (edAmount.getText().toString().equals(""))
                                                            mDbSettings.updateBudgetTotal(0.00);
                                                        else
                                                            mDbSettings.updateBudgetTotal(Double.valueOf((edAmount.getText().toString())));
                                                       
                                                        mDbSettings.close();
                                                       
                                                        setBudgetUsed();
                                                       
                                                    }
                                                });               
   
                 builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog, int whichButton) {
                                                            dialog.cancel();
                                                        }
                                                    });
                
                return builder.show();
            default:
                return null;
        }
         
    }
   
    /** Called each time a dialog is called - use to update dialog's display values*/
    @Override
     protected void onPrepareDialog (int id, Dialog dialog){
       
        //register dialog to activity by calling super
        super.onPrepareDialog(id, dialog);

        switch (id){
                //created when the user clicks on a child item
                case  EDITITEM_DIALOG_ID:
                   
                    //customise the dialog with selected data                   
                    final EditText edItemAmount = (EditText)dialog.findViewById(R.id.BudgetMainEdit_edAmount);
                   
                    dialog.setTitle("Edit\\Delete:\n" + BudgetItem);
                    Toast toast = Toast.makeText(this, String.valueOf(edItemAmount.getSelectionStart()), Toast.LENGTH_SHORT);
                    toast.show();
                    edItemAmount.setText(curDBFormat.format(BudgetAmount));
         
                   
                    break;
                   
                //created when the user selects Edit Budget                   
                case  EDITTOTAL_DIALOG_ID:           
                    //customise the dialog with selected data                   
                    final EditText edTotalAmount = (EditText)dialog.findViewById(R.id.Budget_Dialog_Edit_Total_edTotal);
           
                    edTotalAmount.setText(curDBFormat.format(mBudTotal));       
                   
                   
                default:break;
            }
         }

On Sun, Feb 27, 2011 at 9:51 AM, Justin Anderson <magouyaware@gmail.com> wrote:

The code relevant to the problem... That way we might be able to see what is causing the behavior

On Feb 27, 2011 12:08 AM, "Rajesh Kumar" <rajnitj.garg@gmail.com> wrote:
> May be You r using setText(). Cursor will come to begining position.
>
> On Sat, Feb 26, 2011 at 5:58 PM, Richard Marsh <richardandrewmarsh@gmail.com
>> wrote:
>
>> Which code wold you like to see?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscribe@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

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

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

No comments:

Post a Comment