Displaying Information In Dialog in Android
Hello guys, How are you today? I hope you all be in the best of your life.
Today, we are going to see how to show the information in dialog in Android. So , lets get started.
1) First of all, create an Android Application Project.
2) Next go to "res/layout/activity_main.xml" and create a button for which we are going to implement OnClickListener. The code looks like
3) Next make an Android xml file in the "res/layout/" folder and create a TextView in there. For our case the name is "show.xml" .
4) Next go to "src/your_package_name/MainActivity.java" and implement OnClickListener for the click button. The code looks like
For our case its like
For more info visit on facebook https://www.facebook.com/androidcoolstuffs
Thank you
Today, we are going to see how to show the information in dialog in Android. So , lets get started.
1) First of all, create an Android Application Project.
2) Next go to "res/layout/activity_main.xml" and create a button for which we are going to implement OnClickListener. The code looks like
<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=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:id="@+id/click" />
</RelativeLayout>
3) Next make an Android xml file in the "res/layout/" folder and create a TextView in there. For our case the name is "show.xml" .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You are awesome"
android:textColor="#ffffff"/>
</LinearLayout>
4) Next go to "src/your_package_name/MainActivity.java" and implement OnClickListener for the click button. The code looks like
import android.app.Activity;5) Now, we have to create a class "Show.java" in the "src/your_package_name" . In Show.java we are going to display the show.xml.
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
Button click;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
click = (Button) findViewById(R.id.click);
click.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.click : Intent i = new Intent(this, Show.class);
startActivity(i);
break;
}
}
}
import android.app.Activity;6) Now open AndroidManifest,xml and create an Show Activity with the dialog theme.
import android.os.Bundle;
public class Show extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
}
}
For our case its like
<activity android:theme="@android:style/Theme.Dialog" android:name="com.example.dialog_blog.Show" />Now we are done. Post your questions in the comment. I will be happy to answer those.
For more info visit on facebook https://www.facebook.com/androidcoolstuffs
Thank you
Comments
Post a Comment