I am pretty new to android programming and I am trying to create a simple home screen replacement/launcher.
The application runs fine and the view pager works, but for some reason when I press on any of the image buttons nothing happens.
This is my main activity java class.
package com.dntmdp.matthewhuckel.simplephonelauncher;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity {
Button phone;
Button sms;
Button people;
Button camera;
Button chrome;
Button gallery;
Button mail;
Button calendar;
Button facebook;
Button map;
Button clock;
Button setting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.swipe1);
ImageButton phone = (ImageButton) findViewById(R.id.imageButton);
phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.phone");
startActivity(LaunchIntent);
}
});
ImageButton sms = (ImageButton) findViewById(R.id.imageButton2);
sms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.sonyericsson.conversations");
startActivity(LaunchIntent);
}
});
ImageButton people = (ImageButton) findViewById(R.id.imageButton3);
people.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.sonyericsson.android.socialphonebook");
startActivity(LaunchIntent);
}
});
ImageButton camera = (ImageButton) findViewById(R.id.imageButton4);
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.sonyericsson.android.camera");
startActivity(LaunchIntent);
}
});
setContentView(R.layout.swipe2);
ImageButton chrome = (ImageButton) findViewById(R.id.imageButton5);
chrome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.chrome");
startActivity(LaunchIntent);
}
});
ImageButton gallery = (ImageButton) findViewById(R.id.imageButton6);
gallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.sonyericsson.album");
startActivity(LaunchIntent);
}
});
ImageButton mail = (ImageButton) findViewById(R.id.imageButton7);
mail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.email");
startActivity(LaunchIntent);
}
});
ImageButton calendar = (ImageButton) findViewById(R.id.imageButton8);
calendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.calendar");
startActivity(LaunchIntent);
}
});
ImageButton facebook = (ImageButton) findViewById(R.id.imageButton9);
facebook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.facebook.katana");
startActivity(LaunchIntent);
}
});
ImageButton map = (ImageButton) findViewById(R.id.imageButton10);
map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.apps.maps");
startActivity(LaunchIntent);
}
});
setContentView(R.layout.swipe3);
ImageButton clock = (ImageButton) findViewById(R.id.imageButton11);
clock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.sonyericsson.organizer");
startActivity(LaunchIntent);
}
});
ImageButton setting = (ImageButton) findViewById(R.id.imageButton12);
setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.settings");
startActivity(LaunchIntent);
}
});
setContentView(R.layout.activity_main);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.viewpager_layout);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thank you.