So i have searched and searched and tried every method ive seen but nothing seems to solve my problem. My listview generates with custom adapter, i add the footer view, and onTouchMethod, and i know that it is competing for focus with the lsitview and the listview is winning as i have read about this error. But perhaps there is something i cant see and i am missing.
I need the footer view to be selectable at all times, Right now it is only selectable after an item is selected in listview and then everything works as its suppose to. But on first load on the listview, the footer is unresponsive.
Here is my code.
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);
}
});
my footer button 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" />
Listview 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" >
I have now taken the onTouchMethod out of the OnItemClick of listview and put it above and it receives click on first try. But now the Listview doesnt lose focus when clicked first and then the footer is clicked.