Fragment クラスに onItemClickListener を実装しようとしていますが、残念ながら正しく動作していません...ここにソースコードがあります..何がエラーなのか教えてください??
NetworkDetailsFragment.java (マイ フラグメント クラス)
public class NetworkDetailsFragment extends Fragment implement AdapterView.OnItemClickListener{
private ListView listView;
private View networkDetailsView;
private QOSNetworkDetailsAdapter qosNetworkDetailsAdapter;
private QOSNetworkDetailsDatabaseHelper qosNetworkDetailsDatabaseHelper;
private SimpleCursorAdapter simpleCursorAdapter;
private String LOG_TAG = NetworkDetailsFragment.class.getSimpleName();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i(LOG_TAG, "Inside onCreateView() method");
networkDetailsView = inflater.inflate(R.layout.network_details, container, false);
listView = (ListView) networkDetailsView.findViewById(R.id.list_view);
qosNetworkDetailsDatabaseHelper = new QOSNetworkDetailsDatabaseHelper(getActivity());
Cursor cursor = qosNetworkDetailsDatabaseHelper.getRecord();
String[] columns = {QOSNetworkDetailsDatabaseConstants.COLUMN_NETWORK_TYPE,
QOSNetworkDetailsDatabaseConstants.COLUMN_NETWORK_STATUS,
QOSNetworkDetailsDatabaseConstants.COLUMN_LATITUDE,
QOSNetworkDetailsDatabaseConstants.COLUMN_LONGITUDE,
QOSNetworkDetailsDatabaseConstants.COLUMN_TIME};
int[] to = new int[]{
R.id.networkType,
R.id.networkStatus,
R.id.latitudeAndLongitude,
R.id.date
};
/*SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(
this, R.layout.activity_network_info,
cursor,
columns,
to,
0);*/
simpleCursorAdapter = new SimpleCursorAdapter(getActivity(), R.layout.activity_network_info, cursor, columns, to, 0);
qosNetworkDetailsAdapter = new QOSNetworkDetailsAdapter(getActivity().getApplicationContext(), qosNetworkDetailsDatabaseHelper.getRecord(), false);
listView.setAdapter(qosNetworkDetailsAdapter);
return networkDetailsView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
String countryCode =
cursor.getString(cursor.getColumnIndexOrThrow("code"));
Toast.makeText(getActivity().getApplicationContext(),
countryCode, Toast.LENGTH_SHORT).show();
}
}
network_details.xml (つまり、list_view.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:contentDescription="@string/network_details_fragment_string"
android:descendantFocusability="blocksDescendants" >
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
activity_network_info.xml(list items)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/black"
>
<TextView
android:id="@+id/networkStatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/white"
android:textSize="15sp" />
<TextView
android:id="@+id/networkType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/white"
android:textSize="15sp" />
<TextView
android:id="@+id/latitudeAndLongitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/lightblue"
android:textSize="15sp" />
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/lightblue"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
リストが画面に取り込まれています...しかし、このコードではonItemClickListenerが機能していません...エラーの内容を教えてください..ありがとう