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"
tools:context=".MainActivity"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="105dp"
android:text="@string/c" />
</RelativeLayout>
Activity_Main2.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"
tools:context=".MainActivity2"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/p"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>
Activity_Main3.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"
tools:context=".MainActivity3"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/n"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>
MainActivity.java
package
com.example.prac16;
import
android.os.Bundle;
import
android.app.Activity;
import
android.app.AlertDialog;
import
android.app.Dialog;
import
android.content.DialogInterface;
import
android.content.Intent;
import
android.view.Menu;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
public class
MainActivity extends Activity implements OnClickListener {
Button
b;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button
)findViewById(R.id.button1);
b.setOnClickListener(this);
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main,
menu);
return
true;
}
@Override
public
void onClick(View v) {
AlertDialog.Builder
ad=new AlertDialog.Builder(this);
ad.setMessage("Plese
Select One Activity !");
ad.setNegativeButton("Negative Activity", new
DialogInterface.OnClickListener() {
public
void onClick(DialogInterface dialog,int which) {
Intent
posac1= new Intent(getApplicationContext(),MainActivity3.class);
startActivity(posac1);
}
});
ad.setPositiveButton("Positive Activity", new
DialogInterface.OnClickListener() {
@Override
public
void onClick(DialogInterface arg0, int arg1) {
//
TODO Auto-generated method stub
Intent
posac= new Intent(getApplicationContext(),MainActivity2.class);
startActivity(posac);
}
});
AlertDialog
ald = ad.create();
ald.show();
}
}
0 Comments