【发布时间】:2015-04-06 19:58:42
【问题描述】:
所以我已经搜索和搜索并尝试了我看到的所有方法,但似乎没有任何方法可以解决我的问题。我的列表视图使用自定义适配器生成,我添加了页脚视图和 onTouchMethod,并且我知道它正在与 lsitview 竞争焦点,并且列表视图正在获胜,因为我已经阅读了有关此错误的信息。但也许有些东西我看不到,我错过了。
我需要始终可以选择页脚视图,现在它只有在列表视图中选择了一个项目后才可以选择,然后一切都按预期工作。但是在第一次加载列表视图时,页脚没有响应。
这是我的代码。
customAdapter = new ListAdapter(this, R.layout.itemlistrow, store_data);
customAdapter.setNotifyOnChange(true);
listView.addFooterView(none_of_the_above, null, false);
listView.setAdapter(customAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, final View view,
int position, long id) {
none_of_the_above.setOnTouchListener(new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
v.setSelected(true);
view.setSelected(false);
view.setActivated(false);
view.clearFocus();
Log.e("NoneOFTheAboveButton:onTouch", "clicked");
none_of_the_above.setBackground(getResources().getDrawable(R.drawable.store_setup2_found_selection_boxes_modified_states));
}
return false;
}
});
listView.clearFocus();
none_of_the_above.setSelected(false);
view.setSelected(true);
view.setActivated(true);
selectedPosition = position;
customAdapter.setSelectedPosition(selectedPosition);
}
});
我的页脚按钮 xml
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/none_of_the_above"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/store_setup2_found_selection_boxes_modified_states"
android:focusable="true"
android:clickable="true"
android:text="NONE OF THE ABOVE" />
列表视图 xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selection_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:clickable="false"
android:focusable="false"
android:descendantFocusability="blocksDescendants" >
我现在已经从 listview 的 OnItemClick 中取出 onTouchMethod 并将其放在上面,它会在第一次尝试时收到点击。但是现在 Listview 在先单击然后单击页脚时不会失去焦点。
【问题讨论】:
标签: android listview android-listview android-button