I have been trying to implement splash Screen to my app with help of many codes avaible in sites , but none worked for me.
Each time the app is crashing after displaying splash screen for 3 secs.
I don't know where i'm going wrong , please make corrections to my code to display splash screen correctly ! Thank You !
//This is my Main activity
1. public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button one = (Button) this.findViewById(R.id.gg);
final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.gg);
one.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Good Game", Toast.LENGTH_SHORT).show();
mp1.start();
}
});
Button two = (Button) this.findViewById(R.id.gm);
final MediaPlayer mp2 = MediaPlayer.create(this, R.raw.gm);
two.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Oh, They got me!", Toast.LENGTH_SHORT).show();
mp2.start();
}
});
Button three = (Button) this.findViewById(R.id.cb);
final MediaPlayer mp3 = MediaPlayer.create(this, R.raw.cb);
three.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Come on boy", Toast.LENGTH_SHORT).show();
mp3.start();
}
});
Button four = (Button) this.findViewById(R.id.ns);
final MediaPlayer mp4 = MediaPlayer.create(this, R.raw.ns);
four.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Nice shot", Toast.LENGTH_SHORT).show();
mp4.start();
}
});
Button five = (Button) this.findViewById(R.id.wp);
final MediaPlayer mp5 = MediaPlayer.create(this, R.raw.wp);
five.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "You wanna piece of me!", Toast.LENGTH_SHORT).show();
mp5.start();
}
});
Button six = (Button) this.findViewById(R.id.bi);
final MediaPlayer mp6 = MediaPlayer.create(this, R.raw.bi);
six.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Bring it", Toast.LENGTH_SHORT).show();
mp6.start();
}
});
Button seven = (Button) this.findViewById(R.id.lg);
final MediaPlayer mp7 = MediaPlayer.create(this, R.raw.lg);
seven.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Let’s go, Yeah!", Toast.LENGTH_SHORT).show();
mp7.start();
}
});
Button eight = (Button) this.findViewById(R.id.ru);
final MediaPlayer mp8 = MediaPlayer.create(this, R.raw.ru);
eight.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Ready Up", Toast.LENGTH_SHORT).show();
mp8.start();
}
});
Button nine = (Button) this.findViewById(R.id.nn);
final MediaPlayer mp9 = MediaPlayer.create(this, R.raw.nn);
nine.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Nooooo", Toast.LENGTH_SHORT).show();
mp9.start();
}
});
Button ten = (Button) this.findViewById(R.id.cm);
final MediaPlayer mp10 = MediaPlayer.create(this, R.raw.cm);
ten.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Cover me", Toast.LENGTH_SHORT).show();
mp10.start();
}
});
Button eleven = (Button) this.findViewById(R.id.hh);
final MediaPlayer mp11 = MediaPlayer.create(this, R.raw.hh);
eleven.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Hoo-ya", Toast.LENGTH_SHORT).show();
mp11.start();
}
});
Button twelve = (Button) this.findViewById(R.id.mo);
final MediaPlayer mp12 = MediaPlayer.create(this, R.raw.mo);
twelve.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Move out", Toast.LENGTH_SHORT).show();
mp12.start();
}
});
Button thirteen = (Button) this.findViewById(R.id.gs);
final MediaPlayer mp13 = MediaPlayer.create(this, R.raw.gs);
thirteen.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Get Some", Toast.LENGTH_SHORT).show();
mp13.start();
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Your Messege",Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//This is my activity_main.xml
2. <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.android.mmm.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
//This is content_main.xml
3. <android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.android.mmm.MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000">
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="GG"
android:id="#+id/gg"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/gm"
android:layout_width="100dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:text="GM"
android:textAllCaps="true"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="CB"
android:id="#+id/cb"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="NS"
android:id="#+id/ns"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="WP"
android:id="#+id/wp"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="BI"
android:id="#+id/bi"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="LG"
android:id="#+id/lg"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="RU"
android:id="#+id/ru"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="NN"
android:id="#+id/nn"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="CM"
android:id="#+id/cm"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="HH"
android:id="#+id/hh"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="MO"
android:id="#+id/mo"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="GS"
android:id="#+id/gs"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
//This is AndroidManifest.xml
4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.mmm">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
</application>
//This is styles.xml
5. <resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
//This is my SplashActivity.Java
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
6. //This is activity_splash.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/wwe_logo" />
</RelativeLayout>
AppCompatActivity has it's own toolbar so you need to remove it by using android:theme="#style/AppTheme.NoActionBar" in manifest
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
Although if you are not doing much customization in your toolbar then your can also skip creating your own toolbar by removing it from XML and removing it's initialization from java code as well but by doing this , you will lose the feature of collapsing toolbar
Making a splash screen is actually pretty easy.
1. Create drawable
In my case, I created a drawable named splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorWhite" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/sensesmart_icon" />
</item>
2. Add drawable to your styles.xml
Here I just added my drawable to styles:
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/splash</item>
</style>
3. Add splash to manifest
You want to actually tell your app that the splash layout should show before the app has loaded:
<activity android:name=".BaseActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme"> <!--Splash screen-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
4. Set theme on your starting activity
In my case, BaseActivity is the activity which starts my application, so inside my onCreate(), I start with setting my theme:
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_base);
super.onCreate(savedInstanceState);
}
This is the only thing you need to do. If you use this method, the splash screen doesn't stay for longer than it needs. Your contentView will start as soon as you have loaded your app.
Hope this helps!
Related
I created a basic music player app in Android Studio with the music file stored in the raw directory under resources and Mp3 format.
the issue is that though the toast inside the event listener gets displayed , the audio is not playing except once(i really do not know how).
the code is as below.
the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.basicmusicplayer">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/greetings"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView"
android:layout_width="221dp"
android:layout_height="298dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="104dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:srcCompat="#android:drawable/ic_media_play" />
<Button
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="#string/pause"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/stop"
app:layout_constraintHorizontal_bias="0.565"
app:layout_constraintStart_toEndOf="#+id/play"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:layout_constraintVertical_bias="0.205" />
<Button
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="#string/play"
app:layout_constraintBaseline_toBaselineOf="#+id/pause"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="#string/stop"
app:layout_constraintBaseline_toBaselineOf="#+id/pause"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
the java code
package com.example.basicmusicplayer;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
MediaPlayer player;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
an object of class MediaPlayer created named player
a mp3 file is added to the object using create method*/
player = MediaPlayer.create(this, R.raw.adele);
// setting up inline event listeners to the button
// first comes the play button
Button play_music = findViewById(R.id.play);
play_music.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Playing sound",Toast.LENGTH_SHORT).show();
player.start();
}
});
// adding event listener on pause button
Button pause_music = findViewById(R.id.pause);
pause_music.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "paused sound",Toast.LENGTH_SHORT).show();
player.pause();
}
});
// adding event listener for stop button
Button stop_music = findViewById(R.id.stop);
stop_music.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "stopped sound",Toast.LENGTH_SHORT).show();
player.stop();
}
});
}
}
private MediaPlayer mp;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.button1);
final TextView t = (TextView) findViewById(R.id.textView1);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
stopPlaying();
mp = MediaPlayer.create(PlayaudioActivity.this, R.raw.far);
mp.start();
}
});
}
private void stopPlaying() {
if (mp != null) {
mp.stop();
mp.release();
mp = null;
}
}
I have two Activities MainActivity and Register when i intent from MainActivity to Register the button listener in Register class is not working.
Here is the code
MainActivity
public class MainActivity extends AppCompatActivity {
// defining all the components
AlertDialog builder;
public EditText Email,Password;
public ImageButton fb,twitter;
public Button register;
public String email;
public String password;
public BackgroungWorker backgroungWorker;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
builder = new AlertDialog.Builder(this).create();
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
Email= (EditText) findViewById(R.id.email);
Password= (EditText) findViewById(R.id.pass);
fb= (ImageButton) findViewById(R.id.fb_button);
twitter= (ImageButton) findViewById(R.id.tw_button);
register = (Button) findViewById(R.id.register);
}
// for listening to the events
public void eventHappend(View view)
{
if(view.getId()==R.id.login)
{
email = Email.getText().toString();
password = Password.getText().toString();
if(email.equals(""))
{
showMessage("Error","Email cannot be blank");
return;
}
if(password.equals(""))
{
showMessage("Error","Enter your password");
return;
}
backgroungWorker = new BackgroungWorker(this);
backgroungWorker.execute("Login",email,password);
}
if(view.getId()==R.id.register)
{
// INTENT TO REGISTER ACTIVITY
Intent intent = new Intent(MainActivity.this,Register.class);
startActivity(intent);
}
if(view.getId()==R.id.forgot)
{
}
if(view.getId()== R.id.fb_button)
{
showToast("Facebook!!");
}
if(view.getId()==R.id.tw_button)
{
showToast("Twitter");
}
}
public void showToast(String s)
{
Toast toast = new Toast(this);
toast.makeText(this,s, Toast.LENGTH_SHORT).show();
}
public void showMessage(String title,String message)
{
builder.setTitle(title);
builder.setMessage(message);
builder.setCancelable(true);
builder.show();
}}
Register
public class Register extends Activity {
String user_name,pass,confim_password,email;
AlertDialog builder;
private EditText name,mail,password,confirm_pass;
private Button register;
private BackgroungWorker backgroungWorker;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
mail = (EditText) findViewById(R.id.email);
name = (EditText) findViewById(R.id.name);
password = (EditText) findViewById(R.id.pass);
confirm_pass= (EditText) findViewById(R.id.confirmpass);
register = (Button) findViewById(R.id.register_btn);
builder = new AlertDialog.Builder(this).create();
}
public void registerClicked(View view) // this is not working
{
if(view.getId()==R.id.register_btn)
{
if(name.getText().equals(""))
{
showMessage("Error","Name Cannot be left blank");
return;
}
if(mail.getText().equals(""))
{
showMessage("Error","Email Cannot be left blank");
return;
}
if(password.getText().equals(""))
{
showMessage("Error","Password Cannot be left blank");
return;
}
if(password.getText().equals(confirm_pass.getText().toString()))
{
backgroungWorker = new BackgroungWorker(this);
backgroungWorker.execute("Register",name.getText().toString(),password.getText().toString(),mail.getText().toString());
}
}
}
public void showMessage(String title,String message)
{
builder.setTitle(title);
builder.setMessage(message);
builder.setCancelable(true);
builder.show();
}}
register.xml
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:background=
android:backgroundTint="#02b864">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#02b864">
<ImageView
android:layout_width="212dp"
android:layout_height="176dp"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal"
android:background="#drawable/splash"
android:layout_marginTop="20dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:hint="Name"
android:id="#+id/name"
android:drawableLeft="#drawable/ic_username"
android:drawableTint="#color/colorPrimaryDark"
android:drawablePadding="#dimen/activity_vertical_margin"
android:focusable="true"
android:background="#drawable/editext_bg_gray"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:singleLine="true"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:hint="Email"
android:id="#+id/email"
android:drawableLeft="#drawable/ic_username"
android:drawableTint="#color/colorPrimaryDark"
android:drawablePadding="#dimen/activity_vertical_margin"
android:focusable="true"
android:background="#drawable/editext_bg_gray"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:singleLine="true"
android:layout_marginTop="5dp"
/>
<EditText
android:inputType="textPassword"
android:ems="10"
android:id="#+id/pass"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:hint="Password"
android:drawableLeft="#drawable/ic_pwd"
android:drawablePadding="#dimen/activity_horizontal_margin"
android:drawableTint="#color/colorPrimaryDark"
android:focusable="true"
android:background="#drawable/editext_bg_gray"
android:layout_gravity="center_horizontal"
android:layout_marginRight="25dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp"
android:singleLine="true" />
<EditText
android:inputType="textPassword"
android:ems="10"
android:id="#+id/confirmpass"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:hint="Confirm Password"
android:drawableLeft="#drawable/ic_pwd"
android:drawablePadding="#dimen/activity_horizontal_margin"
android:drawableTint="#color/colorPrimaryDark"
android:focusable="true"
android:background="#drawable/editext_bg_gray"
android:layout_gravity="center_horizontal"
android:layout_marginRight="25dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp"
android:singleLine="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/register_btn"
android:onClick="registerClicked"
android:clickable="true"
android:layout_gravity="center_horizontal"
android:background="#e5e7e8"
android:text="Register"
android:src="#drawable/editext_bg_gray"
android:textColor="#0fbb6c"
android:singleLine="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="50dp"
android:textStyle="normal"
android:textAlignment="center"
android:textSize="22dp"
/>
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>`
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.umarsafdar.dev96.chat">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Splash"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Register"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.DEFAULT" />
</action>
</intent-filter>
</activity>
</application>
</manifest>
thanks in advance.
I have an ImageButton that when I want it to be pressed to launch a second Activity. The second activity is called "Dust 2" as seen in my android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pete.smokesapp" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".homepage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Dust2"
android:label="#string/title_activity_dust2" >
</activity>
</application>
</manifest>
I tried following a guide online but got me as far as this stage now my app crashed on launch.
package pete.smokesapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
public class homepage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
findViewById(R.id.imgDust2).setOnClickListener((View.OnClickListener) this);
}
public void imgDust2(View view) {
switch (view.getId()){
case R.id.imgDust2:
Toast.makeText(this, "Dust 2 Clicked", Toast.LENGTH_LONG ).show();
break;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_homepage, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Here is also my main activity, this is the activity with the ImageButton, i am also new to this so sorry if I seem clueless.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Maps"
android:id="#+id/txtMaps"
android:layout_weight="0.44" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgDust2"
android:clickable="false"
android:src="#drawable/dust2"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgInferno"
android:layout_below="#+id/txtOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp"
android:src="#drawable/inferno" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgOverpass"
android:src="#drawable/overpass"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgMirage"
android:clickable="false"
android:src="#drawable/mirage"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgCache"
android:clickable="false"
android:src="#drawable/cache"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgNuke"
android:clickable="false"
android:src="#drawable/nuke"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
There are two methods available in android using which you can go from one Activity to another.
1. Use button.setOnClickListener()
Create a button in xml file.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Now set event listener for the button in your .class file
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//set the event you want to perform when button is clicked
//you can go to another activity in your app by creating Intent
Intent intent = new Intent(getApplicationContext, Activity2.class);
startActivity(intent);
}
});
2. Use <android:onClick="goNext">
Put the onClick as the attribute of the button you have created in xml file.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="goNext" />
Now in your .class file define an event for that button as,
goNext() {
Intent intent = new Intent(getApplicationContext, Activity2.class);
startActivity(intent);
}
In your first activity do this:
Button button = (Button) findViewById(R.id.imgDust2);
button.setOnClickListener(new View.OnClickListener () {
#Override
public void onClick(View v){
Intent intent = new Intent(v.getContext(), dust2.class);
startActivity(intent);
}
});
Try the following:
Add implements OnClickListener to your class definition: public class homepage extends ActionBarActivity implements OnClickListener
An error will appear and ask you to add unimplemented methods. Do so.
Change findViewById(R.id.imgDust2).setOnClickListener((View.OnClickListener) this); to findViewById(R.id.imgDust2).setOnClickListener(this);
Place the stuff you want to do when the button is clicked into the new method that was added in step 2.
Set onClick to the xml imageView and put the name of the method:
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgDust2"
android:clickable="false"
android:src="#drawable/dust2"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp"
android:onClick="imgDust2"/>
I'm new to Android programming and have been searching this problem for a day now and couldn't come up with a solution. Kindly help me in solving this small problem which is creating a big problem for me.
The error is that when I press the login button in my MainActivity, the app says that unfortunately it has stopped working and the debug window shows an error "Source not found" and further it says ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2249
I've seen similar posts related to this but those posts couldn't help me.
Following my code.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Base.AppCompat.Light.DarkActionBar" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Second"
android:label="#string/title_activity_second" >
</activity>
<activity
android:name=".Registration"
android:label="#string/title_activity_registration" >
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,Second.class);
startActivity(i);
}
});
final Button button2=(Button) findViewById(R.id.button2_id);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent j = new Intent(MainActivity.this,Registration.class);
startActivity(j);
}
});
}
}
MainActivity_xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.firstapp.MainActivity" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/textView1"
android:text="Welcome To Foodparkk"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button_id"
android:layout_below="#+id/textView3"
android:layout_marginTop="45dp"
android:contentDescription="#null"
android:src="#drawable/robo" />
<Button
android:id="#+id/button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/textView3"
android:text="Login" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText3"
android:layout_alignTop="#+id/button2_id"
android:text="E-Mail"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText3"
android:layout_below="#+id/editText3"
android:layout_marginTop="19dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:ems="10"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_id"
android:layout_alignRight="#+id/button_id"
android:layout_marginBottom="42dp"
android:text="Register" />
</RelativeLayout>
activity_second.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.firstapp.Second">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="Select your Meal"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
Second.java
public class Second extends ActionBarActivity implements OnItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
spinner.setOnItemSelectedListener(this);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.food_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
String item = parent.getItemAtPosition(position).toString();
// Showing selected spinner item
Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected (AdapterView<?> parent) {
// code
}
}
In your second.java class you are referencing your layout of main activity
public class Second extends ActionBarActivity implements OnItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Change SetContentView to
setContentView(R.layout.activity_second);
A "Source Not Found" error will be thrown when a class or activity can't be found or instantiated.
Please add the full LogCat log or at least the full ErrorStack.
I have been on this error now for a while. I am trying to open a list view in my dialog but its not opening for me this is my code.
LOGCAST
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mybasicapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Slashscreen"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".menu"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".tutorialsone"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="com.mybasicapp.TUTORIALSONE" />
<category android:name="android.intent.category.DEFAULT" />
Java code:
public class menu extends Activity{
Button ImagebuttonOpenDialog;
String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;
ListView dialog_ListView;
String[] listContent = {
"January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImagebuttonOpenDialog = (Button)findViewById(R.id.imgbtn1);
ImagebuttonOpenDialog.setOnClickListener(new Button.OnClickListener(){
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});
}
#Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(menu.this);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Custom Dialog");
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setOnCancelListener(new OnCancelListener(){
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(menu.this,
"OnCancelListener",
Toast.LENGTH_LONG).show();
}});
dialog.setOnDismissListener(new OnDismissListener(){
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(menu.this,
"OnDismissListener",
Toast.LENGTH_LONG).show();
}});
//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listContent);
dialog_ListView.setAdapter(adapter);
dialog_ListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(menu.this,
parent.getItemAtPosition(position).toString() + " clicked",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);
}});
break;
}
return dialog;
}
#Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog, bundle);
switch(id) {
case CUSTOM_DIALOG_ID:
//
break;
}
}
}
activity_main xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/carbon" >
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="0dp"
android:background="#drawable/bottombar" >
</FrameLayout>
<ImageButton
android:id="#+id/imgbtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="42dp"
android:layout_marginTop="79dp"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imgbtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imgbtn1"
android:layout_marginRight="46dp"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imgbtn1"
android:layout_below="#+id/imgbtn1"
android:layout_marginTop="36dp"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imgbtn2"
android:layout_alignTop="#+id/imageButton3"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton3"
android:layout_below="#+id/imageButton3"
android:layout_marginTop="49dp"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton4"
android:layout_alignTop="#+id/imageButton5"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton5"
android:layout_below="#+id/imageButton5"
android:layout_marginTop="42dp"
android:src="#android:drawable/btn_star" />
<ImageButton
android:id="#+id/imageButton8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton6"
android:layout_alignTop="#+id/imageButton7"
android:src="#android:drawable/btn_star" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/kj" />
custom.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/customdialog"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp"
android:minWidth="300dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<ListView
android:id="#+id/dialoglist"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/kj" />
</LinearLayout>
ALSO
I looked over the java code again and found that my code had (button) where in my XML had image button i have change my java code so you can see where i am at the moment..still no luck.I don't know how to copy log cast
From my count, buttonOpenDialog is null so you are getting NPE when you try to add a listener to it. Check your activity_main that you have a Button with an id of im1. You probably misspelled the id or that one simply doesn't exist in your layout. If you don't see a problem with that then post the activity_main.xml.
Also, this isn't your problem but you should consider using Java standard naming conventions. Class names should start with a capital letter. So you would have Main instead of main as your class name.
When you post a question please post the logcat in your question as it always makes it easier for members to read then needing to follow a link that sometimes isn't of the best quality.