Start Activity from list - launches other activities from list
Activities launcher
public class MainActivity extends ListActivity {
private class Sample {
private CharSequence title;
private Class<? extends Activity> activityClass;
public Sample(int titleResId, Class<? extends Activity> activityClass) {
this.activityClass = activityClass;
this.title = getResources().getString(titleResId);
}
@Override
public String toString() {
return title.toString();
}
}
private static Sample[] mSamples;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Instantiate the list of samples.
mSamples = new Sample[]{
new Sample(R.string.title_first_app, FirstActivity.class),
new Sample(R.string.title_second_app, SecondActivity.class),
new Sample(R.string.title_third_app, ThirdActivity.class),
};
setListAdapter(new ArrayAdapter<Sample>(this,
android.R.layout.simple_list_item_1,
android.R.id.text1,
mSamples));
}
@Override
protected void onListItemClick(ListView listView, View view, int position, long id) {
// Launch the sample associated with this list position.
startActivity(new Intent(MainActivity.this, mSamples[position].activityClass));
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
onSaveInstanceState, onRestoreInstanceState , save preferences
int mCurrentPhotoIndex = 0;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("photo_index", mCurrentPhotoIndex);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
super.onRestoreInstanceState(savedInstanceState);
}
// or save preferences for new start of Activity in onStop
//onCreate or onResume or onStart etc.
public void loadPreferences() {
SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
mCurrentPhotoIndex = settings.getInt("mCurrentPhotoIndex",mCurrentPhotoIndex);
// String_sOtazka = settings.getString("_sOtazka", _sOtazka);
}
// onStop
public void savePreferences() {
SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("mCurrentPhotoIndex", mCurrentPhotoIndex);
// String, boolean, float ...
// editor.putString("mButton1", mButton1.getText().toString());
editor.commit();
}
Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
Calendar cal = new GregorianCalendar();
int era = cal.get(Calendar.ERA); // 0 B.C. before Christ, 1 Anno Domini
txtV.setText(txtV.getText() +"
" + era);
int year = cal.get(Calendar.YEAR); // 2011
txtV.setText(txtV.getText() +"
" + year);
int month = cal.get(Calendar.MONTH); // 0 is Januar
txtV.setText(txtV.getText() +"
" + month);
int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31
txtV.setText(txtV.getText() +"
" + day);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ...
txtV.setText(txtV.getText() +"
" + dayOfWeek);
}
}
Table of usability of mobile phones with Android – February 2012 - (application Sky Map)
1 | Samsung Galaxy S2 | 6.3% |
2 | HTC Desire HD | 3.5% |
3 | HTC Evo 4G | 3.4% |
4 | Samsung Galaxy Ace | 2.1% |
5 | Samsung Galaxy S (SCH-I500) | 2.1% |
6 | Samsung Galaxy S (GT-I9000) | 2.1% |
7 | HTC Incredible 2 | 2.0% |
8 | Motorola Droid X | 1.9% |
9 | Motorola Droid RAZR | 1.9% |
10 | HTC Sensation 4G | 1.7% |
Brand | Samsung |
Model (codename) | i9250 Galaxy Nexus |
Cena, včetně DPH | 9000 |
Veikost Displaye v palcích | 4.65 |
Display-resolution | 1280x720 |
Dotek-typ | kapacitní |
CPU typ | |
CPU MHz | 1200 |
CPU core | 2 |
L2 cache | |
RAM | 1 GB |
ROM | 16 - 32 GB |
GPU | TI OMAP 4460 1,2 GHz dual-core |
NenaMark2 Benchmark | |
GPU-GLBenchmark | |
Baterie mAh | 1750 |
Foto MPx | 5 |
Autofocus | yes |
Video | 480p - 30 frames/s |
Official Android ICS | Android 4.0 Ice Cream Sandwich |
CyanogenMod support | |
Dotek-prstů-max | |
Display-ppi | |
Display-retina | |
Network | GSM&EDGE: 850 / 900 / 1.800 / 1.900 |
Connectivity | |
Pozn. |
samsung-i9250-galaxy-nexus image
// on bottom of onCreate add listener
mInterstitialAd .setAdListener(new AdListener(){
public void onAdLoaded(){
interstitial.show();
}
});
} // end onCreate
public void displayInterstitial (){
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
Editace: 2016-02-25 19:32:45
Počet článků v kategorii: 396
Url:start-activity-from-list-launches-other-activities-from-list