// this is main activity code. I have added list of cars and when clicked it displays the wikipedia about it
package com.example.google_phones;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ListView listView_google_phones;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView_google_phones= (ListView)findViewById(R.id.listView_phones);
final ArrayList<String> arrayList= new ArrayList<>();
arrayList.add("Google Pixel");
arrayList.add("Google Pixel XL");
arrayList.add("Google Pixel 2");
arrayList.add("Google Pixel 2XL");
arrayList.add("Google Pixel 3");
arrayList.add("Pixel_3");
ArrayAdapter arrayAdapter= new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,arrayList);
listView_google_phones.setAdapter(arrayAdapter);
listView_google_phones.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this,wikipedia_search.class);
intent.putExtra("Phone_name", listView_google_phones.getItemAtPosition(position).toString());
startActivity(intent);
}
});
}
}
// this is second activity code when user clicks on any one of the phones
package com.example.google_phones;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class wikipedia_search extends AppCompatActivity {
WebView webView_wiki;
private String search_string;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wikipedia_search);
webView_wiki= (WebView)findViewById(R.id.webView);
webView_wiki.setWebViewClient(new WebViewClient());
Bundle bundle=getIntent().getExtras();
if(bundle!=null){
webView_wiki.loadUrl("http://en.m.wikipedia.org/wiki/"+bundle.getString("Phone_name"));
}
}
}