Skip to content

Instantly share code, notes, and snippets.

@antonshkurenko
Created July 14, 2016 08:08
Show Gist options
  • Save antonshkurenko/7610aad989fe3722e868b160605d3d2d to your computer and use it in GitHub Desktop.
Save antonshkurenko/7610aad989fe3722e868b160605d3d2d to your computer and use it in GitHub Desktop.
Basic activity for demos
package io.github.tonyshkurenko.slidinguppanelsetup;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
static final Demo[] DEMOS = new Demo[] {
new Demo("Sliding up panel library", SlidingUpPanelLibraryActivity.class)
};
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView listView = (ListView) findViewById(R.id.list_view);
if (listView != null) {
listView.setAdapter(
new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, DEMOS));
listView.setOnItemClickListener(this);
}
}
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(this, DEMOS[position].activity));
}
static class Demo {
final String name;
final Class<? extends Activity> activity;
public Demo(String name, Class<? extends Activity> activity) {
this.name = name;
this.activity = activity;
}
@Override public String toString() {
return name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment