【问题标题】:Spinner and ListView in same activitySpinner 和 ListView 在同一个活动中
【发布时间】:2013-09-26 21:47:05
【问题描述】:

我有一个问题,我将其缩小为焦点问题。至少它看起来像一个焦点问题,我可能错了。

声明:

 LogListAdapter adapter;
 Spinner filterTypeMenu;
 ListView list;

创建:

 list = (ListView) findViewById(R.id.loglist);
 filterTypeMenu = (Spinner) findViewById(R.id.spinner1);
 adapter = new LogListAdapter (this, R.layout.row, filteredLogs);
 adapter.notifyDataSetChanged();
 filterTypeMenu.setOnItemSelectedListener(this); // tried with inner class, same result

当我完成我的过程时在我的界面方法中:

 ..
 ..
 adapter.notifyDataSetChanged();
 ..
 ..

并点击监听器:

        @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
            long arg3) {
        // TODO Auto-generated method stub
        Toast.makeText(MainActivity.this, Integer.toString(position),
                Toast.LENGTH_LONG).show();
    }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

我的主要布局:

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
<LinearLayout 
    android:id="@+id/mainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout 
        android:id="@+id/spinnerlayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:entries="@array/filter_array"
            android:prompt="@string/filter"/>

    </LinearLayout>

    <LinearLayout 
        android:id="@+id/listlayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false">

        <ListView
            android:id="@+id/loglist"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false">
        </ListView>
    </LinearLayout>

</LinearLayout>

Notify 方法被反复调用非常快,由于过程的行为,我的列表更新得非常快。当我删除代码的更新块时,微调器的单击事件处于活动状态,但是当更新块处于活动状态时,事件不起作用。我认为这是一个焦点问题,但我不能确定,因为我的菜单是可点击的。问题是当我选择列表中的一个项目时,微调器没有选择该项目并保留旧的选定值,并且单击事件也不起作用。想法将不胜感激。

【问题讨论】:

  • 您在哪里设置了adapter?以及如何填充微调器?
  • list.setAdapter(适配器);并且微调器从 Strings.xml 中的数组填充,尽管我认为微调器中的适配器和值都与这里的问题无关。正如我告诉你的,当我删除 adapter.notifyDataSetChanged() 时,我可以捕获事件。
  • 哦,还有一个补充,大多数时候当我在微调器中选择一个值时,我会看到一条日志“eglsurfaceattrib not implemented”。这可能也是我的解决方案。

标签: android listview focus spinner


【解决方案1】:

有趣的是,我解决了将这两个设置添加到微调器的问题,我确信我之前尝试过,但是哦,android 焦点对我来说仍然是一个半谜。

        filterTypeMenu.setFocusable(true);
        filterTypeMenu.setFocusableInTouchMode(true);

【讨论】:

  • 哦,我的错。我试图用一个标志来停止更新列表,看看它是否有效。列表更新时,我的点击事件仍然无效。标志控件正在工作,但这也带来了另一个问题,因为我无法捕获微调器上的任何事件,甚至它周围的布局,我无法更改标志的值。
猜你喜欢
  • 2012-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
  • 2019-12-17
相关资源
最近更新 更多