我有一個問題,我把它縮小到焦點問題。至少這似乎是一個焦點問題,我可能是錯的。微調和ListView在同一活動
Declerations:
LogListAdapter adapter;
Spinner filterTypeMenu;
ListView list;
的onCreate:
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>
通知方法反覆調用真正的快,我的名單是由於程序的行爲,更新速度相當快。當我刪除代碼的更新塊時,單擊微調器的事件處於活動狀態,但當更新塊處於活動狀態時,事件不起作用。我認爲這是一個焦點問題,但我不能確定,因爲我的菜單是可點擊的。問題是,當我選擇列表中的某個項目時,微調控件不會選擇該項目並保留舊的選定值,並且點擊事件也不起作用。想法將不勝感激。
在哪裏設置你的'適配器'?以及微調如何填補? – RobinHood
list.setAdapter(adapter);並且spinner從Strings.xml中的數組中填充,儘管我認爲spinner中的適配器和值都與此處的問題無關。正如我告訴你,當我刪除adapter.notifyDataSetChanged()我可以捕捉事件。 –
哦,還有一個補充,大多數時候當我選擇一個值在微調,我看到一個日誌「eglsurfaceattrib沒有實施」。這也可能是我的解決方案。 –