Android, menu option with items - android

I have create a menu with couple options, but I want to get a separate page when I click on them in MainActivity. As in: if I click on Movies, I would have other page showing lists of movies and so on.
Which functions should I call for that?
package com.example.popupmenu.popupmenu;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.PopupMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity implements PopupMenu.OnMenuItemClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
public void showPopUp(View v){
PopupMenu popup=new PopupMenu(this,v);
popup.setOnMenuItemClickListener(MainActivity.this);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu. main_menu, popup.getMenu() );
popup.show();
}
#Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.Movies:
Toast.makeText(getApplicationContext(), "movies Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.MeloDramas:
Toast.makeText(getApplicationContext(), "Melodramas Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.Songs:
Toast.makeText(getApplicationContext(), "Songs Selected", Toast.LENGTH_SHORT).show();
return true;
default:
return false;
}
//return false;
}
}

On Your menu Click do this thing to StartActivity.
case R.id.Movies:
Intent launchNewIntent = new Intent(MainActivity.this,SecondActivity.class);
startActivity(launchNewIntent);
return true;
this will open new Activity.

Create a movie list activity. Then in your menuitemclick function in MainActivity, call intent to MovieActivity.
For eg;
Intent intent = new Intent(MainActivity.this, MovieActivity.class);
startActivity(intent);

You can start a new activity by using startActivity. To learn more about starting activities please visit this link.
Intent intent = new Intent(MainActivity.this, MovieActivity.class);
startActivity(intent);

first of all you didn't called showPopUp(View v) you need to call that for inflating menu. and if you want regular menu then why you are using popup menu.. just use this for inflating menu...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.Movies) {
Intent i = new Intent(MainActivity.this,SplashScreen.class);
startActivity(i);
return true;
}
if (id == R.id.MeloDramas) {
Intent i = new Intent(MainActivity.this,melodramas.class);
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
In this case you don't need to call any method just put these two method..

i would advise you to use fragments based on MenuItem selected
public boolean onMenuItemClick(MenuItem item)

Related

Android Tutorial - Adding Action Bar, duplicate class?

I'm trying to create the Action Bar by following the Android Studio tutorial. I am familiar with VBA, C++, and Python, but this is the first time I've ventured into an App, which uses java, xml, etc. in one. I say that because I think I've misplaced (or misnamed) something in my code, as when I try to run this, I get the error error: duplicate class: com.example.batman.myfirstapp.MyActivity.
I don't understand how it's a duplicate, I only have one "MyActivity.java", so am thinking that I can't do more than one public class MyActivity extends ... per .java file?
Here's what I have (please let me know if I need to include other code):
MyActivity.java
package com.example.batman.myfirstapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.support.v7.app.*;
public class MyActivity extends ActionBarActivity{
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
// openSearch();
return true;
case R.id.action_settings:
// openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
public class MyActivity extends AppCompatActivity {
public final static String EXTRA_MESSAGE = ".com.batman.myfirstapp.MESSAGE";
/**
* Called when the user clicks the Send button
*/
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// If your minSdkVersion is 11 or higher, instead use:
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
main_activity_actions.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myfirstapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
myfirstapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
myfirstapp:showAsAction="never" />
</menu>
Again, I'm not sure what other files (strings.xml, DisplayMessageActivity.java, etc.) would be helpful to debug the above, so let me know what else I can include.
Thank you for any advice/help!
You're intuition is correct! You can only have one MyActivity class in your file, here's what it might look like:
public class MyActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = ".com.batman.myfirstapp.MESSAGE";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
return true;
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
Your assumption is correct. In your .java file you have two classes named MyActivity. You can only have one.

Error why working contextual action mode start ActionModeis not applicable for the arguments (ActionMode

I am following a tutorial 11. Exercise: Using the contextual action mode
But I am having this error :
mActionMode = Display.this.startActionMode(mActionModeCallback);
view.setSelected(true);
Error: The method startActionMode(ActionMode.Callback) in the type Activity is not applicable for the arguments (ActionMode.Callback)
I checked this stackoverflow answer
they said to add
ActionBarActivity activity=(ActionBarActivity)getActivity();
activity.startSupportActionMode(modeCallBack);
I had this error
The method getActivity() is undefined for the type Display
what I am doing wrong ? the below is my code.
package com.example.sqlfirst;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.view.ActionMode;
import android.view.ActionMode.Callback;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
public class Display extends ActionBarActivity {
private final static String TAG = "MainActivity";
protected Object mActionMode;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_main);
//have to use getSupportActionBar from android.support.v7.app
// ActionBar actionBar = getSupportActionBar();
//getActionBar().setDisplayHomeAsUpEnabled(true);
ActionBarActivity activity=(ActionBarActivity)getActivity();
activity.startSupportActionMode(modeCallBack);
View view = findViewById(R.id.gridview);
view.setOnLongClickListener(new View.OnLongClickListener() {
// called when the user long-clicks on someView
public boolean onLongClick(View view) {
if (mActionMode != null) {
return false;
}
// start the CAB using the ActionMode.Callback defined above
mActionMode = Display.this.startActionMode(mActionModeCallback);
view.setSelected(true);
return true;
}
});
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Send intent to SingleViewActivity
Intent i = new Intent(getApplicationContext(), SingleViewActivity.class);
// Pass image index
i.putExtra("id", position);
startActivity(i);
} });
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
switch (item.getItemId()){
case R.id.ic_action_person:
Toast.makeText(this, "Create a new account please", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, Register.class);
startActivity(intent);
return true;
case R.id.ic_action_search:
Toast.makeText(this, "Search for new images", Toast.LENGTH_SHORT).show();
Intent isearch= new Intent(this,Search.class);
startActivity(isearch);
return true;
case R.id.ic_action_picture:
Toast.makeText(this, "Search for new photos", Toast.LENGTH_SHORT).show();
Intent iphotos= new Intent(this,Display.class);
startActivity(iphotos);
return true;
}
return true;
}
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
// Called when the action mode is created; startActionMode() was called
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
// assumes that you have "contexual.xml" menu resources
inflater.inflate(R.menu.activity_main_actions, menu);
return true;
}
// called each time the action mode is shown. Always called after
// onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false; // Return false if nothing is done
}
// called when the user selects a contextual menu item
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.ic_action_picture:
Toast.makeText(Display.this, "Selected menu",
Toast.LENGTH_LONG).show();
mode.finish(); // Action picked, so close the CAB
return true;
default:
return false;
}
}
// called when the user exits the action mode
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
}
};
}
Your Display class is extending ActionBarActivity, that means that it´s an Activity so there´s no need to use getActivity(), you can directly make use of the methods like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* this method is available within your ActionBarActivity*/
startSupportActionMode(modeCallBack);
setContentView(R.layout.grid_main);
// The rest of your code comes here
}

Create a button than send the user to the main page

I am new with Android Studio world. I made a two activity pages. The first button in the first page send the user to the second page which it works fine
public void change(View v){
setContentView(R.layout.activity_main_activity2);
but I made the same button in the second page to send the user the main page but no luck. Please see the code and let me know why I got this error.
public void HomePage(View v){
setContentView(R.layout.activity_main_activity);
This is the first activity page
package com.example.lenovo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends ActionBarActivity {
private Menu menu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void change(View v){
setContentView(R.layout.activity_main_activity2);
}
}
and this is the second activity
package com.example.lenovo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import static com.chapter2.example.lenovo.chapter2.R.layout;
public class MainActivity2 extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_main_activity2);
Button mButton = (Button) findViewById(R.id.button2);
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent mIntent = new Intent(MainActivity2.this,
MainActivity.class);
startActivity(mIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity2, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void HomePage (View v){
setContentView(R.layout.activity_main);
}
}
Currently you are switching layouts of Activity instead of changing Activity. this not right way to switch between Activities. use startActivity method with intent to start next Activity on Button click:
Start MainActivity2 from MainActivity:
public void change(View v){
Intent intent=new Intent(v.getContext(),MainActivity2.class);
startActivity(intent);
}
Start MainActivity2 from MainActivity:
public void HomePage(View v){
Intent intent=new Intent(v.getContext(),MainActivity.class);
startActivity(intent);
}
and make sure to have added both Activities in AndroidManifest.xml
If you want use inbuilt device back button then simply put
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
}
and if you want to go back by button click put this line
bbsubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
onBackPressed();
}
});
}
In the first activity you are not launching the mainactivity2.class when you click the button, instead you are just changing the content view.
and the R.id.button2 is not registered in the first activity.
So it is not working
You have to send user first page to second page using Intent
You need to add onClick tag in that button in activity_main layout like this
android:onClick="change"
in activity_main_activity2 add onClick tag in that button like this
android:onClick="HomePage"
In MainActivity2 in setContentView change like this
setContentView(R.layout.activity_main_activity2);
In first activity do like this
public void change(View v){
Intent mIntent = new Intent(MainActivity.this,MainActivity2.class);
startActivity(mIntent);
}
In second activity do like this
public void HomePage(View v){
Intent mIntent = new Intent(MainActivity2.this,MainActivity.class);
startActivity(mIntent);
}
Don't forget to declare those Activities in manifest

Creating Options Menus for Google Glass

Going by the guidelines and conventions in the StopWatch GDK example, I cannot get the MenuOption to open.
My app compiles and able to output the embedded log statement of ""####TEST", but no OptionsMenu appears.
https://developers.google.com/glass/develop/gdk/ui/immersion-menus
This is the method in the Android API for menu's.
openOptionsMenu();
I'm basing the code off of stopwatch's conventions:
/*
*
* Menu Code
*/
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
#Override
public boolean onKeyDown(int keycode, KeyEvent event) {
if (keycode == KeyEvent.KEYCODE_DPAD_CENTER) {
openOptionsMenu();
Log.v("####","TEST");
return true;
}
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Implement if needed
return false;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection. Menu items typically start another
// activity, start a service, or broadcast another intent.
switch (item.getItemId()) {
case R.id.stop:
//startActivity(new Intent(this, StopStopWatchActivity.class));
Log.v("####","HI");
return true;
case R.id.read_aloud:
Log.v("####","READ_ALOUD");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//open the optionsMenu to make sure
#Override
public void openOptionsMenu() {
super.openOptionsMenu();
}
the XML for menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/read_aloud"
android:title="#string/read_aloud"
android:icon="#drawable/ic_launcher"/>
<item
android:id="#+id/stop"
android:title="#string/stop"
android:icon="#drawable/ic_launcher"/>
</menu>
edit: I discovered what my issue was. I commented out the prepared option which was returning false, which caused my options to not engaged.
Here in reference is a good example to do it properly.
Thanks #w9jds for his help.
I can't find what the issue was in my code, but here is a working example solutions with the correct menu creation and one tap.
https://github.com/w9jds/GlassMenuExample
What the program does is show a glass app that renders a hello world card. On Tap the card creates an options menu that has the 'share' option.
This functionality is a lot similar to how cards work on the timeline.
Menu - Main.Xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/share_menu_item"
android:title="#string/share_label"
android:icon="#drawable/ic_share_50"/>
</menu>
Main Activity
package com.example.glassmenuexample;
import com.google.android.glass.app.Card;
import com.google.android.glass.media.Sounds;
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;
import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
public class MainActivity extends Activity
{
private GestureDetector mGestureDetector;
private AudioManager maManager;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//initialize the audio manager
maManager = (AudioManager) getSystemService(this.AUDIO_SERVICE);
//create gesture listener
mGestureDetector = createGestureDetector(this);
//create a new card for the view
Card cView = new Card(this);
//set the text of the card to the hello world string
cView.setText(R.string.hello_world);
//set the card as the content view
setContentView(cView.toView());
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private GestureDetector createGestureDetector(Context context)
{
GestureDetector gdDetector = new GestureDetector(context);
//Create a base listener for generic gestures
gdDetector.setBaseListener( new GestureDetector.BaseListener()
{
#Override
public boolean onGesture(Gesture gesture)
{
if (gesture == Gesture.TAP)
{
//play the tap sound
maManager.playSoundEffect(Sounds.TAP);
//open the menu
openOptionsMenu();
return true;
}
return false;
}
});
return gdDetector;
}
#Override
public boolean onGenericMotionEvent(MotionEvent event)
{
if (mGestureDetector != null)
return mGestureDetector.onMotionEvent(event);
return false;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle item selection. Menu items typically start another
// activity, start a service, or broadcast another intent.
switch (item.getItemId())
{
case R.id.share_menu_item:
//do something on menu item click
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

Selecting Menu Items has no effect

I'm creating an app for Android and I wanted to make items in the context menu.
This wasn't a Problem and they were shown. But when I click on them, nothing happens.
I configured the things I needed to configure, but I really am not able to find the Problem. Do you see something? Here my complete code of the Main-Java-Code.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
public class MainActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl("ABC");}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.optionsmenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem about) {
//respond to menu item selection
switch (R.menu.optionsmenu) {
case R.id.about:
startActivity(new Intent(this, SecondActivity.class));
return true;
case R.id.download:
startActivity(new Intent(this, DownloadActivity.class));
return true;
case R.id.impressum:
startActivity(new Intent(this, ImpressumActivity.class));
case R.id.license:
startActivity(new Intent(this, LicenseActivity.class));
}
return false;
}
I want them to Show the Activitys, but nothing happens.
Thanks for your help
Thanks to Phil, the item selection is now working. Here my other codes, the app breaks down every time I select the others.
Here is LicenseActivity:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
/**
* Created by Florent on 16.08.13.
*/
public class LicenseActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView myWebView = (WebView) findViewById(R.id.licenseview);
myWebView.loadUrl("URL");
}
}
Second Activity is only a design activity, the other activitys are the sames as the License Activity.
I see your misstake. You need to get the menuitems Id inside the switch using MenuItem.getItemId(), and return return super.onOptionsItemSelected();:
public boolean onOptionsItemSelected(MenuItem about) {
//respond to menu item selection
switch (about.getItemId()) { // call this here
case R.id.about:
startActivity(new Intent(this, SecondActivity.class));
return true;
case R.id.download:
startActivity(new Intent(this, DownloadActivity.class));
return true;
case R.id.impressum:
startActivity(new Intent(this, ImpressumActivity.class));
case R.id.license:
startActivity(new Intent(this, LicenseActivity.class));
}
return super.onOptionsItemSelected(about); // return this instead of false
}
Also, do not forget to register your Activities inside your Manifest file.
And make sure you are calling setContentView(...) inside your Activity's onCreate() method.
public class LicenseActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.whateveryourlayoutis); // DONT FORGET THIS
WebView myWebView = (WebView) findViewById(R.id.licenseview);
myWebView.loadUrl("URL");
}
}

Categories

Resources