Back to project page Gents.
The source code is released under:
MIT License
If you think the Android project Gents listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.gsfraley.gents.app.fragments; /*www. j a v a2 s . c o m*/ import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.TextView; import org.gsfraley.gents.R; import org.gsfraley.gents.app.adapters.ServerTypeAdapter; import org.gsfraley.gents.app.main.MainActivity; import org.gsfraley.gents.app.main.MainActivityListener; import org.gsfraley.gents.service.ServerGhost; /** * A fragment representing a list of Items. * <p /> * Large screen devices (such as tablets) are supported by replacing the * ListView with a GridView. * <p /> * Activities containing this fragment MUST implement the {@link Callbacks} * interface. */ public class ServerTypeFragment extends Fragment implements AbsListView.OnItemClickListener { private AbsListView mListView; private ListAdapter mAdapter; private MainActivityListener mListener; /** * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */ public ServerTypeFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mListener = ((MainActivity) getActivity()).getListener(); mAdapter = new ServerTypeAdapter(getActivity()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_servertype, container, false); // Set the adapter mListView = (AbsListView) view.findViewById(android.R.id.list); ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter); // Set OnItemClickListener so we can be notified on item clicks mListView.setOnItemClickListener(this); return view; } @SuppressWarnings("unchecked") @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String classString = ((Class<ServerGhost>) mAdapter.getItem(position)).getName(); mListener.getServerManager().createServer(classString); // Go back to first tab mListener.setTab(0); } /** * The default content for this Fragment has a TextView that is shown when * the list is empty. If you would like to change the text, call this method * to supply the text it should use. */ public void setEmptyText(CharSequence emptyText) { View emptyView = mListView.getEmptyView(); if (emptyText instanceof TextView) { ((TextView) emptyView).setText(emptyText); } } }