AP Assignment 2
AP Assignment 2
Implicit Intent
• For example, you may write the following code to view the webpage. Intent
intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(http://www.javatpoint.com)); startActivity(intent);
Example:-1(IMPLICIT INTENTS)
▪ Step 1: (activity_main.xml)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
<Button android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Visit" />
</LinearLayout>
Step 2: (MainActivity.java)
public class MainActivity extends Activity
{
ASSIGNMENT 2
EditText et1;
Button bt1;
@Override
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.et1); bt1=(Button)findViewById(R.id.bt1);
bt1.setOnClickListener(new OnClickListener()
String url=et1.getText().toString();
}};
Example:-1
Step 1: (activity_main.xml)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<EditText android:id="@+id/et1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<Button android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display" />
</LinearLayout>
Step 2: (MainActivity.java)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.et1);
b1 = (Button) findViewById(R.id.btn1);
b1.setOnClickListener(new OnClickListener()
});
Example:-
♣ Step 1: (activity_main.xml)
<AbsoluteLayout >
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:layout_x="55px"
android:layout_y="361px" />
</AbsoluteLayout>
ϖ Frame Layout:-The FrameLayout is a placeholder on screen that you can use to display
a single view
ASSIGNMENT 2
Example:-
♣ Step 1: (activity_main.xml)
<FrameLayout />
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"/>
</FrameLayout>
Andorid Toast can be used to display information for the short period of time. A toast
contains message to be displayed quickly and disappears after sometime.
You can also create custom toast as well for example toast displaying image. You
can visit next page to see the code for custom toast.
Example
Activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout >
<TextView
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.LENGTH_SHORT).show();