Created
October 5, 2014 11:26
-
-
Save Motoharujap/770bcb12f2541a2dc31a to your computer and use it in GitHub Desktop.
stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.motoharu.cleaningapp; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.support.v4.app.ListFragment; | |
import android.support.v4.app.LoaderManager; | |
import android.support.v4.content.CursorLoader; | |
import android.support.v4.content.Loader; | |
import android.database.Cursor; | |
import android.net.Uri; | |
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.ListView; | |
import android.widget.SimpleCursorAdapter; | |
import android.support.v4.app.LoaderManager.LoaderCallbacks; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import java.sql.SQLException; | |
//This class will show all user information including addresses and name | |
/** | |
* A simple {@link Fragment} subclass. | |
* Activities that contain this fragment must implement the | |
* {@link StatsFragment.OnFragmentInteractionListener} interface | |
* to handle interaction events. | |
* Use the {@link StatsFragment#newInstance} factory method to | |
* create an instance of this fragment. | |
* | |
*/ | |
public class StatsFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { | |
// TODO: Rename parameter arguments, choose names that match | |
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | |
private static final String ARG_PARAM1 = "param1"; | |
private static final String ARG_PARAM2 = "param2"; | |
// TODO: Rename and change types of parameters | |
private String mParam1; | |
private String mParam2; | |
private DBHelper dbhelper; | |
SimpleCursorAdapter adapter; | |
TextView nameTV, secnameTV, surnameTV, accBdTv, accStrTv, accApTv, retBdTv, retStrTv, retApTv; | |
private OnFragmentInteractionListener mListener; | |
/** | |
* Use this factory method to create a new instance of | |
* this fragment using the provided parameters. | |
* | |
* @param param1 Parameter 1. | |
* @param param2 Parameter 2. | |
* @return A new instance of fragment StatsFragment. | |
*/ | |
// TODO: Rename and change types and number of parameters | |
public static StatsFragment newInstance(String param1, String param2) { | |
StatsFragment fragment = new StatsFragment(); | |
Bundle args = new Bundle(); | |
args.putString(ARG_PARAM1, param1); | |
args.putString(ARG_PARAM2, param2); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
public StatsFragment() { | |
// Required empty public constructor | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (getArguments() != null) { | |
mParam1 = getArguments().getString(ARG_PARAM1); | |
mParam2 = getArguments().getString(ARG_PARAM2); | |
} | |
dbhelper = new DBHelper(getActivity()); | |
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService | |
(Context.LAYOUT_INFLATER_SERVICE); | |
View view = inflater.inflate(R.layout.fragment_stats,null); | |
TextView nameTV = (TextView) view.findViewById(R.id.nameStats); | |
Bundle extras = getActivity().getIntent().getExtras(); | |
// long rowID = extras.getLong(DBHelper.MAIN_ID); | |
getActivity().getSupportLoaderManager().initLoader(0, null, this); | |
Cursor data = null; | |
try { | |
data = dbhelper.getUser(5); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
if(data!=null) { | |
nameTV.setText(data.getString(data.getColumnIndexOrThrow(dbhelper.USER_NAME))); | |
} | |
else | |
{ | |
Toast.makeText(getActivity(), "data is null", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
protected void onActivityResult(int requestCode, int resultCode, Intent data, Intent intent) { | |
super.onActivityResult(requestCode, resultCode, intent); | |
if (resultCode == 1) { | |
return; | |
} | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
return inflater.inflate(R.layout.fragment_stats, container, false); | |
} | |
// TODO: Rename method, update argument and hook method into UI event | |
public void onButtonPressed(Uri uri) { | |
if (mListener != null) { | |
mListener.onFragmentInteraction(uri); | |
} | |
} | |
public void fillData(long userid) throws SQLException | |
{ | |
//Cursor cursor = dbhelper.getUser(userid); | |
//String[] from = new String[] {dbhelper.USER_NAME, dbhelper.USER_SECOND_NAME, dbhelper.USER_SURNAME, | |
// dbhelper.ACCEPT_ADDRESS_BD, dbhelper.ACCEPT_ADDRESS_STREET, dbhelper.ACCEPT_ADDRESS_AP, | |
// dbhelper.RETURN_ADDRESS_BD, dbhelper.RETURN_ADDRESS_STREET, dbhelper.RETURN_ADDRESS_AP}; | |
// int[] to = new int[]{R.id.nameStats, R.id.secnameStats, R.id.surnameStats, R.id.accBdStats, R.id.accStreetStats, | |
// R.id.accApStats, R.id.retBdStats, R.id.retStreetStats, R.id.retApStats}; | |
//adapter = new SimpleCursorAdapter(getActivity(), R.layout.fragment_stats, cursor, from, to, 0); | |
// adapter.notifyDataSetChanged(); | |
//cursor.close(); | |
} | |
@Override | |
public void onDetach() { | |
super.onDetach(); | |
mListener = null; | |
} | |
@Override | |
public Loader<Cursor> onCreateLoader(int id, Bundle args) { | |
return new MyCursorLoader(getActivity(), dbhelper); | |
} | |
@Override | |
public void onLoadFinished(android.support.v4.content.Loader<Cursor> cursorLoader, Cursor cursor) { | |
} | |
@Override | |
public void onLoaderReset(android.support.v4.content.Loader<Cursor> cursorLoader) { | |
} | |
/** | |
* This interface must be implemented by activities that contain this | |
* fragment to allow an interaction in this fragment to be communicated | |
* to the activity and potentially other fragments contained in that | |
* activity. | |
* <p> | |
* See the Android Training lesson <a href= | |
* "http://developer.android.com/training/basics/fragments/communicating.html" | |
* >Communicating with Other Fragments</a> for more information. | |
*/ | |
public interface OnFragmentInteractionListener { | |
// TODO: Update argument type and name | |
public void onFragmentInteraction(Uri uri); | |
} | |
static class MyCursorLoader extends CursorLoader { | |
DBHelper db; | |
public MyCursorLoader(Context context, DBHelper db) { | |
super(context); | |
this.db = db; | |
} | |
@Override | |
public Cursor loadInBackground() { | |
Cursor cursor = db.getAllUsers(); | |
return cursor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment