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/googlebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Google" />
<Button
android:id="@+id/yahoobtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/googlebtn"
android:layout_below="@+id/googlebtn"
android:layout_marginTop="65dp"
android:text="Yahoo" />
</RelativeLayout>
MainActivity.java
package com.shrikant.implictintent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button gbtn=(Button)findViewById(R.id.googlebtn);
gbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent google=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.co.in"));
startActivity(google);
}
});
Button ybtn=(Button)findViewById(R.id.yahoobtn);
ybtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent yahoo=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.yahoo.com"));
startActivity(yahoo);
}
});
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.