Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6776395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:01:28+00:00 2026-05-26T16:01:28+00:00

I am using the Edit Text field in my application. when i click on

  • 0

I am using the Edit Text field in my application. when i click on it the soft keyboard appears.but when i click on the “DONE” button (which is on soft keyboard ),it should be disappear but it does not disappear.i set the input type as text in the layout file.I want to hide the soft keyboard when i press button.
please help.Thanks in advance.

Here is my code.

public class locupdate extends MapActivity implements OnDoubleTapListener{

    GeoPoint p,geoPoint;
    MapView SearchMap;
    List<Overlay> list;
    MapController map_controller;
    LocationManager locationManager;
    Location location,update_location ;
    MyLocationOverlay me;
    Button go_btn,done;
    String city;
    int cid;
    Double lat_update,lng_update;
    EditText location_entered;
    @Override
    public void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        setContentView(R.layout.bingmapupdate);
        go_btn=new Button(getApplicationContext());
        go_btn=(Button)findViewById(R.id.go_button);

        location_entered=(EditText)findViewById(R.id.enterLocationforSearch); 
        location_entered.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                location_entered.setText("");

            }
        });
        done=new Button(getApplicationContext());
        done=(Button)findViewById(R.id.button_locationUpdateDone);
        done.setEnabled(false);
        done.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor=preferences.edit();
                String memberid=preferences.getString("unique_userName", null);

                String lat=Double.toString(lat_update);
                String lang=Double.toString(lng_update);
                editor.putString(memberid+"LATITUDE",lat);
                editor.putString(memberid+"LONGITUDE",lang);
                //editor.putLong(memberid+"LATITUDE",lat_update);
                //editor.putLong(memberid+"LONGITUDE",lng_update);

                editor.commit();
                //editor.putString("Location", update_location);

                //update the "lat_update" , "lng_update" and "update_location" with UID(cell_id)

                Intent i=new Intent();
                i.setClassName("some pkg name here", "some activity name here");
                startActivity(i);

                finish();

            }
        });

        SearchMap= (MapView)findViewById(R.id.View_map);
        //SearchMap.setTraffic(true);
        SearchMap.setBuiltInZoomControls(true);
        map_controller=SearchMap.getController();
        SearchMap.setClickable(false);
        map_controller.setZoom(10);

        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = SearchMap.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);     
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        geoPoint=new GeoPoint((int)(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6));
        p=geoPoint;

        // map_controller.animateTo(geoPoint);

        // SearchMap.invalidate();

        go_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                location_entered=new EditText(getApplicationContext());
                location_entered=(EditText)findViewById(R.id.enterLocationforSearch);

                String area=location_entered.getText().toString();
                BingMapLocationUpdateActivity.this.changeMap(area);
                SearchMap.setClickable(true);

            }
        });

    }

    protected class MapOverlay extends com.google.android.maps.Overlay {
        @Override
        public boolean draw(Canvas canvas,MapView map,boolean shadow,long when){

            p=geoPoint;
            //map_controller.animateTo(geoPoint);
            Paint paint=new Paint();
            super.draw(canvas, map, shadow);
            Point myScreenCoords = new Point();
            map.getProjection().toPixels(p, myScreenCoords);
            paint.setStrokeWidth(1);
            paint.setARGB(255, 255, 255, 255);
            paint.setStyle(Paint.Style.STROKE);
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
            canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
            canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
            return true;
        }
        @Override
        public boolean onTouchEvent(MotionEvent event,MapView SearchMap)
        {   
            //Toast.makeText(BingMapLocationUpdateActivity.this,
            //  "Touch Event Listener called",
            //  Toast.LENGTH_SHORT).show();

            SearchMap.setClickable(true);

            drawMarker(event);
            done.setEnabled(true);

            return false;
        }

    }/*--------------------------------------end of overlay class------------------------------------*/
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    @Override
    protected void onDestroy() {
        super.onStop();
    }
    @Override
    public boolean onDoubleTap(MotionEvent event) {
        drawMarker(event);
        Toast.makeText(BingMapLocationUpdateActivity.this,
                "onDoubleTap called",
                Toast.LENGTH_LONG).show();
        return false;
    }
    @Override
    public boolean onDoubleTapEvent(MotionEvent event) {
        drawMarker(event);
        Toast.makeText(BingMapLocationUpdateActivity.this,
                "onDoubleTapEvent called",
                Toast.LENGTH_LONG).show();

        return false;
    }
    @Override
    public boolean onSingleTapConfirmed(MotionEvent event) {
        // TODO Auto-generated method stub

        drawMarker(event);
        Toast.makeText(BingMapLocationUpdateActivity.this,
                "Single Tap Event Listener called",
                Toast.LENGTH_LONG).show();
        return false;
    }
    /*-------------------------------------------get clicked location and draw marker---------------------------*/
    public void drawMarker(MotionEvent event){
        GeoPoint p = SearchMap.getProjection().fromPixels((int) event.getX(),(int) event.getY());
        //Toast.makeText(getBaseContext(),p.getLatitudeE6() / 1E6 + "," +p.getLongitudeE6() /1E6 ,Toast.LENGTH_SHORT).show();
        /*save these latitude and longitude*/
        lat_update=p.getLatitudeE6() / 1E6;
        lng_update=p.getLongitudeE6() /1E6;

        //lat_update=(long)(p.getLatitudeE6() / 1E6);
        //lng_update=(long)(p.getLongitudeE6() /1E6);

        int X = (int)event.getX();          
        int Y = (int)event.getY();
        geoPoint = SearchMap.getProjection().fromPixels(X, Y);
        //map_controller.animateTo(geoPoint);

        //int lac = cellLocation.getLac();


        // me = new MyLocationOverlay(getApplicationContext(), SearchMap);
        getLocationName(p);

    }
    /*-----------------------------------getLocationName method----------------------------------------*/
    public void getLocationName(GeoPoint point_city){
        float latitude = point_city.getLatitudeE6() / 1000000F;
        float longitude = point_city.getLongitudeE6() / 1000000F;

        location.setLatitude(latitude);
        location.setLongitude(longitude);

        Geocoder gcd = new Geocoder(this,Locale.getDefault()) ;
        List<Address> addresses = null;
        try {
            addresses = gcd.getFromLocation(point_city.getLatitudeE6() / 1E6 , point_city.getLongitudeE6() /1E6, 1);
            //addresses = gcd.getFromLocation(latitude,longitude,5);
            if (addresses.size() > 0) 
                city=addresses.get(0).getAddressLine(0);
            String state=addresses.get(0).getAddressLine(1);
            String country=addresses.get(0).getAddressLine(2);
            String sb;
            sb=city+""+state+""+country;
            //Toast.makeText(getApplicationContext(),sb,Toast.LENGTH_SHORT).show();


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        location_entered.setText(city);
        /*save city in shared preferences*/
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor=preferences.edit();
        editor.putString("city",city);
        editor.commit();

    }

    /*-------------------------------------------Change Map Method---------------------------------------*/

    public void changeMap(String area)
    {

        GeoPoint myLocation=null;

        double lat = 0;
        double lng = 0;
        try
        {

            Geocoder g = new Geocoder(this, Locale.getDefault());

            List<Address> result=g.getFromLocationName(area,5);
            if(result.size()>0){

                //Toast.makeText(BingMapLocationUpdateActivity.this, "country: " + String.valueOf(result.get(0).getCountryName()), Toast.LENGTH_SHORT).show();

                lat = result.get(0).getLatitude();
                lng = result.get(0).getLongitude();
                myLocation=new GeoPoint((int)(lat*1e6),(int)(lng*1e6));
                map_controller.animateTo(myLocation);

            }            
            else{
                Toast.makeText(BingMapLocationUpdateActivity.this, "record not found", Toast.LENGTH_SHORT).show();
                return;
            }
        }
        catch(IOException io)
        {
            Toast.makeText(BingMapLocationUpdateActivity.this, "Connection Error", Toast.LENGTH_SHORT).show();
        }

        //Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);

        map_controller.setZoom(12);
        //SearchMap.invalidate();
    }


}

my layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/bingmapupdate_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#FFFFFF"
        android:text="Google Maps"
        android:textColor="#ff000000" >
    </TextView>

    <EditText
        android:id="@+id/enterLocationforSearch"
        android:layout_width="170dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bingmapupdate_label"
        android:layout_marginTop="30dp"
        android:layout_toLeftOf="@+id/go_button"
        android:layout_toRightOf="@+id/enterLocation_label"
        android:inputType="text"
        android:singleLine="true"
        android:text="search" >
    </EditText>

    <com.google.android.maps.MapView
        android:id="@+id/View_map"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/enterLocationforSearch"
        android:apiKey="GOOGLE_API_KEY" >
    </com.google.android.maps.MapView>

    <Button
        android:id="@+id/go_button"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/enterLocationforSearch"
        android:layout_alignBottom="@+id/enterLocationforSearch"
        android:layout_alignParentRight="true"
        android:background="@drawable/btn_ng"
        android:text="Go" >
    </Button>

    <Button
        android:id="@+id/button_locationUpdateDone"
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/btn_ng"
        android:text="DONE" >
    </Button>

    <TextView
        android:id="@+id/enterLocation_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/enterLocationforSearch"
        android:layout_alignBottom="@+id/enterLocationforSearch"
        android:layout_marginLeft="20dp"
        android:text="Enter City"
        android:textColor="#111111" >
    </TextView>

</RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:01:29+00:00Added an answer on May 26, 2026 at 4:01 pm

    I use this function:

    public static void hideSoftInput(Context ctx)
    {
        InputMethodManager inputManager = (InputMethodManager) ctx.getSystemService(INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(new View(ctx).getWindowToken(), 0);
    }
    

    For your particular case, you can use this:

        location_entered.setOnKeyListener(new View.OnKeyListener() 
        {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) 
            {
                if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                {
                    // code to hide the soft keyboard
                    InputMethodManager imm = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
                }
                return false;
            }
        });
    

    after this part on your onCreate:

      location_entered.setOnClickListener(new View.OnClickListener() {
      [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jquery how do I focus the first element (edit field, text area, dropdown
I have a text file that I want to edit using Java. It has
I am using Komodo Edit , a code editor. When I right click on
I am developing an application which should work under different languages (german, spanish, etc).
I am using jqgrid throughout my application. On two screens with inline edit, everything
I'm using Visual Studio 2008. I'm currently working with WPF and I'm using Edit->Format
I need to edit (using javascript) an SVG document embedded in an html page.
I've been using Komodo Edit for a small project in Django. The code completion
I have recently been working with Python using Komodo Edit and other simpler editors
I'm using markdown to edit this question right now. In some wikis I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.