我正在显示一个带有edittext视图的对话框.但是,仅当用户按下编辑视图内部时,才会打开软键盘.所以我尝试使用以下代码调用InputMethodManager.
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(dialogField,0);
Run Code Online (Sandbox Code Playgroud)
dialogField是输入字段.但是,我到底应该这样做呢?我在对话框的onStart()方法中尝试了它,但没有任何反应.我之前也尝试过请求对话框的焦点,但这没有任何改变.
我也试过这段代码
dialogField.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
public void onFocusChange (View v, boolean hasFocus)
{
if (hasFocus)
{
Main.log("here");
dialogInput.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
/*
InputMethodManager mgr =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(dialogField,0);
*/
}
}
});
Run Code Online (Sandbox Code Playgroud)
在两个版本中.但是没有软键盘会出现.Main.log只是一个日志,它向我显示该函数实际被调用.是的,它被称为.
在对话框打开之前,我可以使用SHOW_FORCED标志获取键盘.但是在退出时它不会关闭.而且我只能在显示对话框之前这样做.在任何回调中它也不起作用.
我想要这样的东西:
所以问题是,我真正想要的是当用户在搜索视图中输入特定主题名称(如果存在于应用程序中)时,它应该能够提供建议,如果找到它应该打开该主题活动(就像 Facebook、Instagram 等)搜索..这些标题来自API(我已在其他活动中成功显示)..像这样:
..它的逻辑是什么???需要帮助...谢谢
所以我刚刚像这样在 XML 中包含了 searchview-->
<SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint="Search Here"
android:iconifiedByDefault="false"
android:layout_alignParentTop="true"
android:background="@drawable/search_bar"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:pointerIcon="crosshair"
android:theme="@style/Widget.AppCompat.SearchView"
android:focusedByDefault="true"
/>
Run Code Online (Sandbox Code Playgroud)
需要帮助...提前致谢....
这是我的 json:
[{"id":"11","title":"TextView"},{"id":"10","title":"Edit Text"},{"id":"9","title":"ImageView"},{"id":"8","title":"Button "},{"id":"7","title":"CheckBox"},{"id":"6","title":"RadioButton & RadioGroup"},{"id":"5","title":"DatePicker"},{"id":"4","title":"TimePicker"},{"id":"3","title":"Switch"},{"id":"1","title":"Simple & Custom Toast"}]
Run Code Online (Sandbox Code Playgroud)
这是我的活动:对于
public class StartLearning extends AppCompatActivity {
private RecyclerView recyclerView;
private SLAdapter slAdapter;
ProgressDialog progressDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startlearning_layout);
progressDialog = new ProgressDialog(StartLearning.this);
progressDialog.setMessage("Loading....");
progressDialog.show();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != …Run Code Online (Sandbox Code Playgroud)