Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中隐藏软键盘_Android_Android Edittext_Hide_Android Softkeyboard - Fatal编程技术网

如何在android中隐藏软键盘

如何在android中隐藏软键盘,android,android-edittext,hide,android-softkeyboard,Android,Android Edittext,Hide,Android Softkeyboard,我正在应用程序中使用编辑文本字段。当我点击它时,软键盘出现。但当我点击“完成”按钮(软键盘上的)时,它应该消失,但不会消失。我在布局文件中将输入类型设置为文本。我想在按下按钮时隐藏软键盘。 请帮忙,谢谢 这是我的密码 public class locupdate extends MapActivity implements OnDoubleTapListener{ GeoPoint p,geoPoint; MapView SearchMap; List<Overl

我正在应用程序中使用编辑文本字段。当我点击它时,软键盘出现。但当我点击“完成”按钮(软键盘上的)时,它应该消失,但不会消失。我在布局文件中将输入类型设置为文本。我想在按下按钮时隐藏软键盘。 请帮忙,谢谢

这是我的密码

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();
    }


}
public类蝗虫更新扩展了MapActivity实现OnDoubleTapListener{
地球点p,地球点;
地图视图搜索地图;
名单;
地图控制器地图控制器;
地点经理地点经理;
位置-位置,更新位置;
我的位置比我高;
按钮开始,完成;
字符串城市;
int-cid;
双lat_更新,lng_更新;
编辑输入的文本位置;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bingmapupdate);
go_btn=新建按钮(getApplicationContext());
go_btn=(按钮)findViewById(R.id.go_按钮);
输入的位置=(EditText)findViewById(R.id.enterLocationforSearch);
位置\u已输入。setOnClickListener(新视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
输入的位置。setText(“”);
}
});
完成=新建按钮(getApplicationContext());
完成=(按钮)findViewById(R.id.Button\u LocationUpdateOne);
完成。设置启用(false);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
SharedReferences preferences=PreferenceManager.GetDefaultSharedReferences(getApplicationContext());
SharedReferences.Editor=首选项.edit();
String memberid=preferences.getString(“唯一用户名”,null);
字符串lat=Double.toString(lat_更新);
字符串lang=Double.toString(lng\u更新);
编辑器.putString(memberid+“纬度”,lat);
putString(memberid+“经度”,lang);
//编辑器.putLong(memberid+“纬度”,纬度更新);
//编辑器.putLong(memberid+“经度”,lng_更新);
commit();
//编辑器.putString(“位置”,更新位置);
//使用UID(单元格id)更新“lat_更新”、“lng_更新”和“更新位置”
意图i=新意图();
i、 setClassName(“此处的某些包装名称”、“此处的某些活动名称”);
星触觉(i);
完成();
}
});
SearchMap=(MapView)findViewById(R.id.View\u map);
//SearchMap.setTraffic(true);
SearchMap.SetBuilTinZoomControl(真);
map_controller=SearchMap.getController();
SearchMap.setClickable(false);
地图控制器。设置缩放(10);
MapOverlay MapOverlay=新的MapOverlay();
List listOfOverlays=SearchMap.getOverlays();
listOfOverlays.clear();
添加(映射覆盖);
locationManager=(locationManager)getSystemService(Context.LOCATION\u服务);
location=locationManager.getLastKnownLocation(locationManager.GPS\U提供程序);
地理点=新的地理点((int)(location.getLatitude()*1e6),(int)(location.getLatitude()*1e6));
p=地质点;
//映射控制器。动画到(地球点);
//SearchMap.invalidate();
go_btn.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
输入的位置=新编辑文本(getApplicationContext());
输入的位置=(EditText)findViewById(R.id.enterLocationforSearch);
字符串区域=输入的位置。getText().toString();
BingMapLocationUpdateActivity.this.changeMap(区域);
SearchMap.setClickable(true);
}
});
}
受保护类MapOverlay扩展了com.google.android.maps.Overlay{
@凌驾
公共布尔绘制(画布、地图视图、布尔阴影、长时间){
p=地质点;
//映射控制器。动画到(地球点);
油漆=新油漆();
超级。绘制(画布、地图、阴影);
点myScreenCoords=新点();
map.getProjection().toPixels(p,myScreenCoords);
油漆。设置行程宽度(1);
setARGB(255、255、255、255);
绘制.设置样式(绘制.样式.笔划);
位图bmp=BitmapFactory.decodeResource(getResources(),R.drawable.marker);
drawBitmap(bmp,myScreenCoods.x,myScreenCoods.y,paint);
drawText(“我在这里…”,myscreencoods.x,myscreencoods.y,paint);
返回true;
}
@凌驾
公共布尔onTouchEvent(MotionEvent事件,MapView SearchMap)
{   
//Toast.makeText(BingMapLocationUpdateActivity.this,
//“已调用触摸事件侦听器”,
//吐司。长度(短)。show();
SearchMap.setClickable(true);
标志(事件);
done.setEnabled(true);
返回false;
}
}/*--------------------------------------覆盖类结束------------------------------------*/
@凌驾
受保护的布尔值isRouteDisplayed(){
//TODO自动生成的方法存根
返回false;
}
@凌驾
受保护的空onDestroy(){
super.onStop();
}
@凌驾
公共布尔onDoubleTap(运动事件){
标志(事件);
Toast.makeText(BingMapLocationUpdateActivity.this,
“onDoubleTap调用”,
Toast.LENGTH_LONG).show();
返回false;
}
@凌驾
公共布尔OnDoubleTapeEvent(运动事件){
标志(事件);
Toast.makeText(BingMapLocationUpdateActivity.this,
“在
<?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>
public static void hideSoftInput(Context ctx)
{
    InputMethodManager inputManager = (InputMethodManager) ctx.getSystemService(INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(new View(ctx).getWindowToken(), 0);
}
    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;
        }
    });
  location_entered.setOnClickListener(new View.OnClickListener() {
  [...]
      getWindow().setSoftInputMode(
      WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);