Android Open Source - Stem-Esteem Stem List Fragment






From Project

Back to project page Stem-Esteem.

License

The source code is released under:

GNU General Public License

If you think the Android project Stem-Esteem listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package whipkey.stemesteem.components;
//from w ww . j  a  v  a 2s  .  c  om
//Copyright 2011, Zackary Whipkey
//This program/source is distributed under the terms of the GNU General Public License.
//Please read the License.txt file for more information.

import whipkey.stemesteem.R;
import whipkey.stemesteem.db.StemDbAdapter;
import whipkey.stemesteem.db.StemDbHelper;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

/**
 * 
 * StemListFragment hosts the listview that displays the stems for the current
 * week. It is displayed in the StemEsteem activity. An implementation of
 * StemEsteem.java's filldata() could be moved to here. It's current function
 * exists in a callback.
 * 
 */

public class StemListFragment extends ListFragment {
  StemListItemClickListener clickListener;

  public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {
      clickListener = (StemListItemClickListener) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString()
          + "needs to implement StemListItemClickListener");
    }
  }

  public interface StemListItemClickListener {
    public void stemListItemClick(int weekNo, int stemNo, String stem);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.stemlistfragment, container);

    return v;
  }

  public void onDestroy() {
    super.onDestroy();
  }

  public void onListItemClick(ListView l, View v, int position, long id) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) l.getAdapter();
    Cursor c = adapter.getCursor();

    c.moveToPosition(position);
    int weekNo = c.getInt(c.getColumnIndex("weekNo"));
    int stemNo = c.getInt(c.getColumnIndex("stemNo"));
    String stem = c.getString(c.getColumnIndex("stem"));
    clickListener.stemListItemClick(weekNo, stemNo, stem); // call back to
                                // our activity,
                                // requesting
                                // the
                                // currentWeek's
                                // value so that
                                // our listview
                                // can be
                                // updated.
  }

}




Java Source Code List

whipkey.stemesteem.components.EndingAddDialog.java
whipkey.stemesteem.components.EndingEditDialog.java
whipkey.stemesteem.components.EndingListFragment.java
whipkey.stemesteem.components.StemListFragment.java
whipkey.stemesteem.db.StemDbAdapter.java
whipkey.stemesteem.db.StemDbHelper.java
whipkey.stemesteem.db.StemProvider.java
whipkey.stemesteem.main.EndingListActivity.java
whipkey.stemesteem.main.StemEsteemApplication.java
whipkey.stemesteem.main.StemEsteem.java