Back to project page ProjectStudio.
The source code is released under:
Apache License
If you think the Android project ProjectStudio 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 fragments; /*w w w .java 2 s.c o m*/ import android.app.AlertDialog; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.widget.DrawerLayout; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import com.example.uniutilproject.R; import java.sql.SQLException; import DB_Provider.ProfessorDataSource; import adapters.ProfessorCardAdapter; /** * @author desmond * TODO ADD AN ONCLICK LISTENER TO EACH "SEE MORE" ITEM IN EACH PROFESSOT ITEM * TODO WHEN ITEM IS CLICKED, A NEW FRAGMENT WILL OPEN AND SHOW DETAILS OF EACH PROFESSOR */ public class ProfessorsFragment extends Fragment { private ListView professors_listview; private DrawerLayout parent_drawer; private ProfessorDataSource dataSource; private ProfessorCardAdapter adapter; private static final int REQUEST_CODE = 1; private AlertDialog.Builder build; private Cursor cursor; ViewGroup parent_view; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.professors_fragment, container, false); //CALL DTABASE dataSource = new ProfessorDataSource(getActivity()); try { dataSource.open(); } catch (SQLException e) { e.printStackTrace(); } //IF DRAWER HAS BEEN DISABLED BY SOME OTHER FRAGMENT //ENABLE DRAWER parent_drawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout); if (parent_drawer.getDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) == 0) { parent_drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); } professors_listview = (ListView) view .findViewById(R.id.professors_listview); new android.os.Handler().post(new Runnable() { @Override public void run() { cursor = dataSource.getAllProfessors(); parent_view = ((ViewGroup) getView().getParent()); adapter = new ProfessorCardAdapter(getActivity(), cursor, true, parent_view); professors_listview.setAdapter(adapter); adapter.notifyDataSetChanged(); } }); /*professors_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long l) { } }); */ dataSource.close(); return view; } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { /* switch (requestCode) { //MAKE SURE FRAGMENT CODES MATCH UP case REQUEST_CODE: Bundle bundle = data.getExtras(); Toast.makeText(getActivity(), "id : " + bundle.getLong("confirmation_id") + " inserted correctly", Toast.LENGTH_LONG).show(); break; } */ //Bundle bundle = this.getArguments(); } // Register the fragment as a contributor to the Options Menu // call setHasOptions within its onCreate Handler @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } // add a menu item when this fragment is called @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); // custom menu (action bar layout) inflater.inflate(R.menu.professors_menu_fragment, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); // Find which menu item has been selected switch (item.getItemId()) { // Check for each known menu item case R.id.professors_menu_addbtn: showChildFragment(); return true; // Return false if the menu item has not been handled default: return false; } } // private void showChildFragment() { FragmentManager fm = getFragmentManager(); AddProfFragment frag = new AddProfFragment(); FragmentTransaction transaction = fm.beginTransaction(); // For a little polish, specify a transition animation transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); Log.e("fragment", ((ViewGroup) getView().getParent()).getId() + " "); transaction.replace(((ViewGroup) getView().getParent()).getId(), frag).addToBackStack(null).commit(); } @Override public void onResume() { try { dataSource.open(); } catch (SQLException e) { e.printStackTrace(); } super.onResume(); } @Override public void onPause() { dataSource.close(); super.onPause(); } //REMOVE THE THREE DOT ICON FROM THE ACTIONBAR, SINCE IT IS NOT NEEDED FOR NOW @Override public void onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.action_settings); item.setVisible(false); Log.e("actionbar", " Professors "); getActivity().getActionBar().setTitle(" Professors "); super.onPrepareOptionsMenu(menu); } }