0

我有一个问题,我把它缩小到一个焦点问题。至少它看起来像一个焦点问题,我可能是错的。

声明:

 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>

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

4

1 回答 1

1

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

        filterTypeMenu.setFocusable(true);
        filterTypeMenu.setFocusableInTouchMode(true);
于 2013-09-26T13:47:05.117 回答