小编Mar*_*nks的帖子

Android:点击按钮后隐藏键盘

单击按钮后我需要隐藏android键盘.

我已经看过许多如何做到这一点的例子,但是,它们似乎都使用了特定的editText对象.

例如

InputMethodManager imm = (InputMethodManager)getSystemService(
      Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)

我的问题是我正在动态构建屏幕,因此可能存在鬃毛编辑文本字段.有没有办法隐藏键盘而不必指定我隐藏它的editText对象.

keyboard android hide

25
推荐指数
5
解决办法
6万
查看次数

Android:ListFragment:如何刷新列表

我有一个列表显示在片段上.我在屏幕底部有一个按钮,当按下该按钮时,将调用web服务以重新获取任何其他数据.如果有其他数据,我需要将其添加到列表视图中.我搜索了这个论坛和许多其他网站试图找到如何做到这一点,但我没有成功.任何帮助深表感谢.

我现在正在考虑是否需要在dyncamically中添加片段,而不是在以下XML布局上定义它.

我正在使用ListFragment来扩展屏幕上的列表视图.

我有一个屏幕上有两个片段.屏幕的XML如下: -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <fragment
            android:name="atos.mobilereporting.com.ReportList"
            android:layout_width="323dp"
            android:layout_height="match_parent" />

        <fragment
            android:name="atos.mobilereporting.com.ReportDetail"
            android:layout_width="958dp"
            android:layout_height="match_parent" />
    </LinearLayout>


    <Button
        android:id="@+id/getReports"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Refresh Mobile Reports" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

膨胀视图的代码如下: -

 public class ReportList extends ListFragment {

      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Get list of reports...
            repList = ReportDefinitionFactory.buildReportList(3);

            activity = getActivity();

            ListAdapter la = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_1,
                    ReportDefinitionFactory.getReportDescriptions(repList));

            setListAdapter(la);

        }

    }
Run Code Online (Sandbox Code Playgroud)

此代码显示一个简单的列表视图,其中包含3行.

在这一点上,我必须停下来,因为我不知道是不是要离开这里.我有一些代码,它将向用于初始构建列表视图的数组添加一个额外的行,但我不知道如何在列表视图上调用刷新.

谢谢

马丁

android android-listfragment

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

android-listfragment ×1

hide ×1

keyboard ×1