activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_height="match_parent"
android:weightSum="10"
tools:context="com.example.krazz.colprac5.MainActivity"> <!-- write proper context-->
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:text="Newspapers"
android:textSize="22dp"
android:gravity="center"
android:background="@color/colorAccent"/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:background="@color/colorAccent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_height="match_parent"
android:weightSum="10"
tools:context="com.example.krazz.colprac5.MainActivity"> <!-- write proper context-->
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:text="Newspapers"
android:textSize="22dp"
android:gravity="center"
android:background="@color/colorAccent"/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:background="@color/colorAccent"/>
</LinearLayout>
MainActivity.java :
package com.example.krazz.colprac5; //keep your package as it is and copy from next line
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] data={"The Times of India","The Financial Express","Gujarat Samachar","Sandesh","Hindustan","Dainik Jagran"};
lv=(ListView)findViewById(R.id.lv);
ArrayAdapter ad=new ArrayAdapter(getApplicationContext(),android.R.layout.simple_list_item_1,data);
lv.setAdapter(ad);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent ii=new Intent(MainActivity.this,Main2Activity.class);
if(i==0)
{
ii.putExtra("link","http://timesofindia.indiatimes.com/topic/English-newspaper");
startActivity(ii);
}
else if(i==1)
{
ii.putExtra("link","http://www.financialexpress.com/");
startActivity(ii);
}
else if(i==2)
{
ii.putExtra("link","http://www.gujaratsamachar.com/");
startActivity(ii);
}
else if(i==3)
{
ii.putExtra("link","http://www.sandesh.com/");
startActivity(ii);
}
else if(i==4)
{
ii.putExtra("link","http://www.livehindustan.com/");
startActivity(ii);
}
else if(i==5)
{
ii.putExtra("link","http://www.jagran.com/");
startActivity(ii);
}
}
});
}
}
activity_main2.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.example.krazz.colprac5.Main2Activity"><!-- change to your context-->
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</LinearLayout>
Main2Activity.java :
package com.example.krazz.colprac5;//keep your package as it is and copy from next line
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
public class Main2Activity extends AppCompatActivity {
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
web = (WebView) findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
web.loadUrl(getIntent().getStringExtra("link"));
}
}
AndroidManifest.xml :
add the line shown below just above <application> tag
<uses-permission android:name="android.permission.INTERNET"/>