我有一个FragmentActivity,它在EditText和Button上面加载了一个ListL,包含ListView.我似乎无法让键盘显示在任何方法中.当我触摸它或设置焦点时,没有任何反应.当我自动请求焦点时,没有任何反应.如何让键盘出现?这不应该是自动的吗?我想模拟GTALK的聊天输入.
activity_contact_chat.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal" >
<Button
android:id="@+id/details_record_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/chat_message_input"
android:text="Send" />
<EditText
android:id="@+id/chat_message_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/details_record_button"
android:ems="10"
android:gravity="top|left"
android:hint="@string/message_hint"
android:lines="1"
android:maxLines="10"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:scrollbars="vertical" >
</EditText>
<ListView
android:id="@+id/messages_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/chat_message_input"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#000000" >
</ListView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
ContactChatFragment:
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import …Run Code Online (Sandbox Code Playgroud) 最近在开发应用程序时,我遇到了一个问题.我在谷歌搜索了很多,但找不到任何解决方案.最后,我遇到了这个Android问题跟踪器
为了解释我的问题,我做了一个示例App.
我的示例应用程序的基本工作
我想要实现的目标
我是如何实现这一目标的
wasEditing = true.wasEditing = true.wasEditing,如果是,我请求焦点为EditText.imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT,resultRec)我遇到问题的地方
有时在执行此调用后,键盘在少数情况下不可见,例如在方向更改期间.
当我把日志我发现这个函数返回false
但是,如果我有这样的showSoftInput()电话使用100毫秒的延迟一些mEditText.postDelayed()在onResume()一切工作正常.
问题 在什么情况下此函数返回false并且为什么延迟有效?
注意 虽然我已经使用延迟解决了我的问题,但我仍然想知道为什么它表现得那样.
我有一个ListAdapter,在这种情况下包含一个项目.该项生成一个具有EditText的视图.
当视图显示时,我想打开软键盘以允许用户编辑该字段.
我试着调用适配器的getView()函数:
View edittext = view.findViewById(R.id.EditText01);
edittext.requestFocus();
mInputMgr.showSoftInput(edittext, InputMethodManager.SHOW_FORCED);
Run Code Online (Sandbox Code Playgroud)
这似乎没有做任何事情.
我也尝试过:
View edittext = view.findViewById(R.id.EditText01);
edittext.requestFocus();
mInputMgr.toggleSoftInput(0, 0);
Run Code Online (Sandbox Code Playgroud)
这产生了一个神秘的原因,一个循环,其中软键盘可重复打开和关闭.
当我删除requestFocus并触摸点击程序中的EditText时,它会弹出软键盘,但是看看requestFocus是否存在,showSoftInput似乎不起作用.
我需要做什么?
list元素的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:focusable="true"
android:background="@color/light_blue"
>
<EditText android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:text=""
android:focusable="true"
android:layout_width="fill_parent" android:inputType="textShortMessage"></EditText>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
包含ListView的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
>
<Button android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Button01"
android:gravity="center_horizontal"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
long getView函数:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有自己的键盘,所以我想一直隐藏软件键盘(在特定的活动和对话框中).我尝试了两个选项:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
此代码阻止键盘在开始时弹出,但是当我单击文本框时,键盘仍会弹出.
InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
此代码隐藏键盘,但它不会阻止键盘弹出.
请帮忙!
我有一个游戏,它使用C++回调来强制打开软键盘,当用户触摸屏幕时.Java代码就是这样的:
this._inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Run Code Online (Sandbox Code Playgroud)
这已经好了一段时间,但最近我们收到一些摩托罗拉Droid用户的抱怨,软键盘无法为他们打开.由于我们最近才开始接受这些投诉,而且我认为这是对这些设备进行某种更新.
有没有更好的方法可以强制键盘打开?我在网上找到的所有链接都谈到使用文本框控件等,但我的应用程序主要是C++,根本不使用标准控件.
为什么我无法在我的活动中显示虚拟键盘.这是我的代码:
package som.android.keypad;
import android.app.Activity;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
public class ShowKeypad extends Activity {
InputMethodManager imm;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
EditText editText = (EditText)findViewById(R.id.EditText);
((InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE)).showSoftInput(editText, 0);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="som.android.keypad"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ShowKeypad"
android:windowSoftInputMode="stateAlwaysVisible"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
Run Code Online (Sandbox Code Playgroud) 我正在使用我的应用程序中的编辑文本字段.当我点击它时出现软键盘.但是当我点击"完成"按钮(在软键盘上)时,它应该消失但它不会消失.我将输入类型设置为布局文件中的文本.我想按下按钮时隐藏软键盘.请帮忙.谢谢.
这是我的代码.
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 …Run Code Online (Sandbox Code Playgroud)