Android Open Source - Android-Sessions Main Activity






From Project

Back to project page Android-Sessions.

License

The source code is released under:

MIT License

If you think the Android project Android-Sessions 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 uk.ac.icappsoc.appsoctwo;
/* w  w  w  .  j a v a2  s.  c om*/
import uk.ac.icappsoc.appsoctwo.circleimage.CircleImageActivity;
import uk.ac.icappsoc.appsoctwo.circleimage.SessionTitleActivity;
import uk.ac.icappsoc.appsoctwo.rainbowtv.RainbowTextViewActivity;
import uk.ac.icappsoc.appsoctwo.split.SplitActivity;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * A simple list activity.
 * In this case, displays a list of other activities in this project
 * and lets you jump to those.
 */
public class MainActivity extends ListActivity {

  /** A list of all the other activities we want to put in our list. */
  private Class<?>[] activities = {SessionTitleActivity.class, RainbowTextViewActivity.class, SplitActivity.class, CircleImageActivity.class};
  /** An adapter that populates a list with Views that it creates. */
  private DemoAdapter adapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    adapter = new DemoAdapter();
    // Populate our list with the data in our adapter
    setListAdapter(adapter);
  }
  
  /** Called whenever one of the list items is clicked. */
  @Override
  protected void onListItemClick(ListView list, View view, int position, long id){
    // Start the selected Activity
    Intent intent = new Intent(this, activities[position]);
    startActivity(intent);
  }
  
  /* Extending BaseAdapter is a good choice when in need of an adapter. */
  private class DemoAdapter extends BaseAdapter {
    
    @Override
    public int getCount() {
      return activities.length;
    }

    // No need to return anything special.
    @Override
    public Object getItem(int position) {
      return null;
    }

    // No need to anything special.
    @Override
    public long getItemId(int position) {
      return 0;
    }
    
    // Creates the Views that actually populate the list
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      if(null == convertView){
        // Our view has not been recycled, let's create a new one!
        convertView = getLayoutInflater().inflate(R.layout.item_list_image, null);
      }
      // Update recycled or old view
      TextView label = (TextView) convertView.findViewById(R.id.text);
      label.setText(activities[position].getSimpleName());
      
      return convertView;
    }
    
  }
}




Java Source Code List

uk.ac.icappsoc.appsocone.MainActivity.java
uk.ac.icappsoc.appsocthree.MainActivity.java
uk.ac.icappsoc.appsocthree.SensorListActivity.java
uk.ac.icappsoc.appsocthree.accel.BouncyBallView.java
uk.ac.icappsoc.appsocthree.accel.Gravity2DActivity.java
uk.ac.icappsoc.appsocthree.accel.ShakeActivity.java
uk.ac.icappsoc.appsocthree.compass.CompassActivity.java
uk.ac.icappsoc.appsocthree.compass.CompassView.java
uk.ac.icappsoc.appsocthree.light.LightClockActivity.java
uk.ac.icappsoc.appsocthree.proximity.ProximityActivity.java
uk.ac.icappsoc.appsoctwo.MainActivity.java
uk.ac.icappsoc.appsoctwo.circleimage.CircleImageActivity.java
uk.ac.icappsoc.appsoctwo.circleimage.CircleImageView.java
uk.ac.icappsoc.appsoctwo.circleimage.SessionTitleActivity.java
uk.ac.icappsoc.appsoctwo.rainbowtv.RainbowTextViewActivity.java
uk.ac.icappsoc.appsoctwo.rainbowtv.RainbowTextView.java
uk.ac.icappsoc.appsoctwo.split.SplitActivity.java
uk.ac.icappsoc.appsoctwo.split.SplitGameView.java