这是我的布局文件,其中所有参数都需要防止元素被点击(至少我认为它们都是)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal" >
<TextView
android:id="@+id/measuredata_list_row_textview_date"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.0"
android:gravity="center"
android:clickable="false"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/measuredata_list_row_textview_time"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.0"
android:gravity="center"
android:clickable="false"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/measuredata_list_row_textview_value"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.0"
android:gravity="center"
android:clickable="false"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/measuredata_list_row_imageview_mood"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:clickable="false"
android:focusable="false"
android:contentDescription="@string/imageview_photo_description" />
</LinearLayout>
以及活动中的代码:
public class MeasureDataListFragment extends Fragment implements OnClickListener, OnItemClickListener, MeasureDataGetSelectionCallback, MeasureDataGetCallback {
private SessionManagerPreferences sessionManagerPreferences = null;
private SessionManagerSingleton sessionManagerSingleton = null;
private SessionManagerMeasureDataList sessionManagerMeasureDataList = null;
private MeasureDataListAdapter adapter = null;
private ListView listRowParent = null;
private Button buttonChoose = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.sessionManagerPreferences = new SessionManagerPreferences(this.getActivity());
this.sessionManagerSingleton = SessionManagerSingleton.getInstance(this.getActivity());
this.sessionManagerMeasureDataList = SessionManagerMeasureDataList.getInstance();
if(this.sessionManagerMeasureDataList.getMeasureDataList() == null) {
this.sessionManagerMeasureDataList.setMeasureDataList(new MeasureDataList());
}
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_measuredata_list_fragment, container, false);
}
@SuppressLint("InflateParams")
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.listRowParent = (ListView) view.findViewById(R.id.measuredata_list_row_parent);
this.buttonChoose = (Button) view.findViewById(R.id.measuredata_list_fragment_button_choose);
this.buttonChoose.setOnClickListener(this);
this.adapter = new MeasureDataListAdapter(this.getActivity(), this.sessionManagerMeasureDataList.getMeasureDataList().getMeasureDataListEntries());
this.listRowParent.setAdapter(this.adapter);
this.listRowParent.setOnItemClickListener(this);
}
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.measuredata_list_fragment_button_choose : {
this.performChooseDates();
} break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("MeasureDataListFragment", "Position: " + position);
}
@Override
public void onMeasureDataGetSelectionCompleted(final String fromYear, final String fromMonth, final String fromDay, final String toYear, final String toMonth, final String toDay) {
String email = null;
String password = null;
String from = fromDay + "." + fromMonth + "." + fromYear;
String to = toDay + "." + toMonth + "." + toYear;
if(this.sessionManagerSingleton.isLoggedIn()) {
email = this.sessionManagerSingleton.getEmail();
password = this.sessionManagerSingleton.getPassword();
} else {
Map<String, String> userData = this.sessionManagerPreferences.getUserDetails();
email = userData.get(Globals.KEY_EMAIL);
password = userData.get(Globals.KEY_PASSWORD);
}
FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
MeasureDataGetTask measureDataGetTask = new MeasureDataGetTask(email, password, from, to);
MeasureDataGetDialogFragment measureDataGetDialogFragment = new MeasureDataGetDialogFragment(measureDataGetTask, this);
measureDataGetDialogFragment.show(fragmentTransaction, null);
}
@Override
public void onMeasureDataGetCompleted(StatusMeasureDataGet status, MeasureDataGetPOJO measureDataGetPOJO) {
switch(status) {
case MEASUREDATA_TRANSFER_SUCCESSFUL: {
this.sessionManagerMeasureDataList.setMeasureDataList(measureDataGetPOJO);
this.adapter.notifyDataSetChanged();
} break;
case ERROR_CONNECTION_FAILED: {
String title = this.getResources().getString(R.string.title_error);
String message = this.getResources().getString(R.string.message_connection_failed);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
case ERROR_IO_EXCEPTION: {
String title = this.getResources().getString(R.string.title_error);
String message = this.getResources().getString(R.string.message_io_exception);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
case ERROR_JSON_EXCEPTION: {
String title = this.getResources().getString(R.string.title_error);
String message = this.getResources().getString(R.string.message_json_exception);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
case ERROR_NO_DATA_FOUND: {
String title = this.getResources().getString(R.string.title_error);
String message = this.getResources().getString(R.string.message_not_data_found);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
case ERROR_PROTOCOL_EXCEPTION: {
String title = this.getResources().getString(R.string.title_error);
String message = this.getResources().getString(R.string.message_protocol_exception);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
case ERROR_WRONG_PARAMETERS: {
String title = this.getResources().getString(R.string.title_error);
String message = this.getResources().getString(R.string.message_wrong_parameters);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
case ERROR_WRONG_USER_OR_PW: {
String title = this.getResources().getString(R.string.title_input_error);
String message = this.getResources().getString(R.string.message_wrong_mail_or_pw);
DialogManager.showAlertDialog(title, message, this.getFragmentManager());
} break;
}
}
private void performChooseDates() {
FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
MeasureDataSelectionDialogFragment measureDataGetSelectionDialogFragment = new MeasureDataSelectionDialogFragment(this);
measureDataGetSelectionDialogFragment.show(fragmentTransaction, null);
}
}
不幸的是,我的所有行都没有响应来自OnItemClickListener的点击。 我还有什么可以解决这个问题?单击任何行时,日志文件根本没有输出。它就像我从未向ListView添加OnItemClickListener。