Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

Code to show hyphen(-) after every four digits of entered number in EditText,android

->    Here in my requirement when ever i entered CreditCard number in my EditText,a Hyphen(-) will be added after entering every four digits in my EditText.just refer below image..

this code will work even in "Samsung galaxy s3 " latest Android version devices also..
EditText cardNumber=(EditText) findViewById(R.id.cardNumber);
cardNumber.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {
                //XXX do something                
            }
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {
                //XXX do something                

            }
            public void onTextChanged(CharSequence s, int start, int before, int count) {                                                  
                showImage(cardNumber.getText().toString());

                ///Code  set listener for BackButton
                /*cardNumber.setOnKeyListener(new OnKeyListener() {                
                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {

                        if(keyCode != KeyEvent.KEYCODE_DEL && cardNumber.getText().length() !=0)
                        {*/
                            if(cardNumber.getText().length()==5 ||cardNumber.getText().length()==10 ||cardNumber.getText().length()==15 ||cardNumber.getText().length()==20)
                            {                            
                                tempString=cardNumber.getText().toString()+"-";
                                char c=tempString.charAt(tempString.length()-2);

                                if(c!='-')
                                {
                                    stringArray = tempString.toCharArray();                   
                                    stringArray[tempString.length()-2]=stringArray[tempString.length()-1];
                                    stringArray[tempString.length()-1]=c;

                                    //code to convert charArray back to String..
                                    tempString=new String(stringArray);
                                    cardNumber.setText(tempString);            
                                    cardNumber.setSelection(tempString.length());
                                    tempString=null;
                                }

                            }
                        /*}

                        return false ;      
                    }
                });*/

            }
        });




 <EditText
                        android:id="@+id/cardNumber"
                        android:layout_width="fill_parent"
                        android:layout_height="47dip"
                        android:layout_below="@+id/cardHolderName"
                        android:layout_marginLeft="25dip"
                        android:layout_marginRight="25dip"
                        android:gravity="center_vertical"
                        android:hint="Card Number*"
                        android:inputType="number"
                        android:maxLength="24"
                     
                        android:singleLine="true"
                        android:textSize="15dip" />

Comments

Post a Comment