Android Open Source - local-stories List Fragment






From Project

Back to project page local-stories.

License

The source code is released under:

Apache License

If you think the Android project local-stories 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 no.hiof.stud.localstories;
/*from   w w  w. j a va  2 s . c o m*/
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
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.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListFragment extends Fragment {
  public final static String EVENT_ID = "1";

  @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    }
    
    @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
      // Inflate the layout for this fragment
        return inflater.inflate(R.layout.list_fragment, container, false);
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Fragment frag = getFragmentManager().findFragmentByTag("list_Fragment");
        final ListView listview = (ListView) frag.getView().findViewById(R.id.listView1);
      
      ArrayList<Event> events = Search.getList();
      String[] values = new String[events.size()];
      for(int i=0; i<events.size(); i++){
        values[i] = events.get(i).header;
      }

      StableArrayAdapter adapter = new StableArrayAdapter(getActivity(),
          R.layout.item, R.id.label, values);
      listview.setAdapter(adapter);

      listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View view,
      int position, long id) {
      
      String ide = Search.getList().get((int) id).id+"";
      Intent intent = new Intent(getActivity(), EventActivity.class);
      intent.putExtra(EVENT_ID, ide);
      startActivity(intent);
        }

      });
    }

    public class StableArrayAdapter extends ArrayAdapter<String> {

      HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

      public StableArrayAdapter(Context context, int viewResourceId, int textViewResourceId,
          String[] values) {
        super(context, viewResourceId, textViewResourceId, values);
        for (int i = 0; i < values.length; ++i) {
          mIdMap.put(values[i], i);
        }
      }

      @Override
      public long getItemId(int position) {
        String item = getItem(position);
        return mIdMap.get(item);
      }

      @Override
      public boolean hasStableIds() {
        return true;
      }
    }
}




Java Source Code List

no.hiof.stud.localstories.ArticleFragment.java
no.hiof.stud.localstories.AudioFragment.java
no.hiof.stud.localstories.DisplayMessageActivity.java
no.hiof.stud.localstories.DisplayPhoto.java
no.hiof.stud.localstories.EventActivity.java
no.hiof.stud.localstories.Event.java
no.hiof.stud.localstories.Library.java
no.hiof.stud.localstories.ListFragment.java
no.hiof.stud.localstories.Load.java
no.hiof.stud.localstories.LocationManagerHelper.java
no.hiof.stud.localstories.MainActivity.java
no.hiof.stud.localstories.MapFragment.java
no.hiof.stud.localstories.MyItemizedOverlay.java
no.hiof.stud.localstories.MyOwnItemizedOverlay.java
no.hiof.stud.localstories.PhotosFragment.java
no.hiof.stud.localstories.Picture.java
no.hiof.stud.localstories.PlayAudio.java
no.hiof.stud.localstories.RangeSeekBar.java
no.hiof.stud.localstories.Search.java