Make click events on the profile list available to the Activity
If the Activity this fragment is placed in implements the provided interface it is notified about clicks on any of the profiles.
This commit is contained in:
@@ -53,6 +53,14 @@ public class VpnProfileListFragment extends Fragment
|
||||
private VpnProfileDataSource mDataSource;
|
||||
private VpnProfileAdapter mListAdapter;
|
||||
private ListView mListView;
|
||||
private OnVpnProfileSelectedListener mListener;
|
||||
|
||||
/**
|
||||
* The activity containing this fragment should implement this interface
|
||||
*/
|
||||
public interface OnVpnProfileSelectedListener {
|
||||
public void onVpnProfileSelected(VpnProfile profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -62,6 +70,7 @@ public class VpnProfileListFragment extends Fragment
|
||||
|
||||
mListView = (ListView)view.findViewById(R.id.profile_list);
|
||||
mListView.setEmptyView(view.findViewById(R.id.profile_list_empty));
|
||||
mListView.setOnItemClickListener(mVpnProfileClicked);
|
||||
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
|
||||
mListView.setMultiChoiceModeListener(mVpnProfileSelected);
|
||||
mListView.setAdapter(mListAdapter);
|
||||
@@ -93,6 +102,17 @@ public class VpnProfileListFragment extends Fragment
|
||||
mDataSource.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity)
|
||||
{
|
||||
super.onAttach(activity);
|
||||
|
||||
if (activity instanceof OnVpnProfileSelectedListener)
|
||||
{
|
||||
mListener = (OnVpnProfileSelectedListener)activity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
@@ -138,6 +158,17 @@ public class VpnProfileListFragment extends Fragment
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private final OnItemClickListener mVpnProfileClicked = new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> a, View v, int position, long id)
|
||||
{
|
||||
if (mListener != null)
|
||||
{
|
||||
mListener.onVpnProfileSelected((VpnProfile)a.getItemAtPosition(position));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final MultiChoiceModeListener mVpnProfileSelected = new MultiChoiceModeListener() {
|
||||
private HashSet<Integer> mSelected;
|
||||
private MenuItem mEditProfile;
|
||||
|
||||
Reference in New Issue
Block a user