0

I am aware that this question has been asked before, but I have tried every "solution" to the other questions, but I still have not been able to achieve what I am trying to do. I have searched and searched, and tried and tried. Please forgive me. I simply want to display my row of buttons above my WebView, so that it is consistent with the rest of the activities in my app (they all have the row of buttons at the top). It seems like I have tried every possible combination of layouts, but to no avail. It displays correctly in the Graphical Layout (Eclipse), but on the phone and emulator it only displays the WebView, fullscreen, no buttons.... Any help will be very much appreciated!

Here's my xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:orientation="horizontal" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/menu_panel">


                    <ImageButton
                        android:id="@+id/bHomeMenu"
                        android:layout_margin="-8dip"
                        android:layout_width="65dp"
                        android:layout_height="90dp"
                        android:background="@drawable/menu_btn_hcu_light_blue"
                        android:src="@drawable/icon_menu_home"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        style="@style/ButtonText"
                        android:textSize="13sp"
                        android:text="Home" />

                    <ImageButton
                        android:id="@+id/bItsMe247Menu"
                        android:layout_toRightOf="@+id/bHomeMenu"
                        android:layout_margin="-8dip"
                        android:layout_width="65dp"
                        android:layout_height="90dp"
                        android:background="@drawable/menu_btn_selected_hcu_light_blue"
                        android:src="@drawable/icon_menu_login"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        style="@style/ButtonText"
                        android:textSize="13sp"
                        android:text="It'sMe" />

                    <ImageButton
                        android:id="@+id/bFindUsMenu"
                        android:layout_toRightOf="@+id/bItsMe247Menu"
                        android:layout_margin="-8dip"
                        android:layout_width="65dp"
                        android:layout_height="90dp"
                        android:background="@drawable/menu_btn_hcu_light_blue"
                        android:src="@drawable/icon_menu_find_us"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        style="@style/ButtonText"
                        android:textSize="13sp"
                        android:text="FindUs" />

                    <ImageButton
                        android:id="@+id/bEmailMenu"
                        android:layout_toRightOf="@+id/bFindUsMenu"
                        android:layout_margin="-8dip"
                        android:layout_width="65dp"
                        android:layout_height="90dp"
                        android:background="@drawable/menu_btn_hcu_light_blue"
                        android:src="@drawable/icon_menu_email"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        style="@style/ButtonText"
                        android:textSize="13sp"
                        android:text="Email" />

                    <ImageButton
                        android:id="@+id/bRatesMenu"
                        android:layout_toRightOf="@+id/bEmailMenu"
                        android:layout_margin="-8dip"
                        android:layout_width="65dp"
                        android:layout_height="90dp"
                        android:background="@drawable/menu_btn_hcu_light_blue"
                        android:src="@drawable/icon_menu_rates"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        style="@style/ButtonText"
                        android:textSize="13sp"
                        android:text="Rates" />




    </LinearLayout>


                        <WebView xmlns:android="http://schemas.android.com/apk/res/android"
                            android:id="@+id/wvItsMe"
                            android:layout_width="fill_parent"
                            android:layout_height="0dp"
                            android:layout_weight="1" />


</LinearLayout>

EDIT: Here's my java code, and a note below it:

    package com.dummyapp.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.dummyapp.app.SimpleGestureFilter.SimpleGestureListener;

public class ItsMe247 extends Activity implements SimpleGestureListener{

    private SimpleGestureFilter detector;

    private WebView itsMeLogin;

//  ImageButton menuHome, menuFindUs, menuEmail, menuRates;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.itsme247);

//      menuHome = (ImageButton)findViewById(R.id.bHomeMenu);
//      menuFindUs = (ImageButton)findViewById(R.id.bFindUsMenu);
//      menuEmail = (ImageButton)findViewById(R.id.bEmailMenu);
//      menuRates = (ImageButton)findViewById(R.id.bRatesMenu);



        detector = new SimpleGestureFilter(this,this);

        itsMeLogin = new WebView(this);

        Toast.makeText(this, "Just Swipe To Exit", Toast.LENGTH_LONG).show();


        itsMeLogin.getSettings().setJavaScriptEnabled(true); // JavaScript enabled

        getWindow().requestFeature(Window.FEATURE_PROGRESS); // Show progress bar of page loading

        final Activity itsMeActivity = this;


        itsMeLogin.setWebChromeClient(new WebChromeClient() {

            public void onProgressChanged(WebView view, int progress){

                // Activities and WebViews measure progress with different scales.
                // The progress meter will automatically disappear when we reach 100%
                itsMeActivity.setProgress(progress * 100);

            }

        });

        itsMeLogin.setWebViewClient(new WebViewClient(){

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){

                Toast.makeText(itsMeActivity, "Oh no! " + description, Toast.LENGTH_SHORT).show();

            }


        });

        itsMeLogin.loadUrl("http://www.google.com");
        setContentView(itsMeLogin);


//      itsMeLogin.setWebViewClient(new WebViewClient() {
//          @Override
//          public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
//              return super.shouldOverrideUrlLoading(view, url);
//          }
//      });



//******************* MENU BUTTONS START HERE ********************************************************//        

//      menuRates.setOnClickListener(new View.OnClickListener() {
//          
//          public void onClick(View v) {
//              // TODO Auto-generated method stub
//              Intent ratesIntent = new Intent(ItsMe247.this, Rates.class);
//              ItsMe247.this.startActivity(ratesIntent);
//              
//          }
//          
//      });
//      
//      
//      menuFindUs.setOnClickListener(new View.OnClickListener() {
//          
//          public void onClick(View v) {
//              // TODO Auto-generated method stub
//              Intent contactIntent = new Intent(ItsMe247.this, Contact.class);
//              ItsMe247.this.startActivity(contactIntent);
//              
//          }
//      });
//      
//      menuEmail.setOnClickListener(new View.OnClickListener() {
//          
//          public void onClick(View v) {
//              // TODO Auto-generated method stub
//              Intent emailIntent = new Intent(ItsMe247.this, Email.class);
//              ItsMe247.this.startActivity(emailIntent);
//              
//
//          }
//      });
//      
//      menuHome.setOnClickListener(new View.OnClickListener() {
//          
//          public void onClick(View v) {
//              // TODO Auto-generated method stub
//              Intent itsMeIntent = new Intent(ItsMe247.this, MainActivity.class);
//              ItsMe247.this.startActivity(itsMeIntent);
//          }
//      });


//***************************** MENU BUTTONS END HERE ********************************************************//


    }//end onCreate method


    @Override 
      public boolean dispatchTouchEvent(MotionEvent me){ 
        this.detector.onTouchEvent(me);
       return super.dispatchTouchEvent(me); 
      }


        public void onSwipe(int direction) {

                   switch (direction) {

                   case SimpleGestureFilter.SWIPE_RIGHT: 

                       Intent funIntent = new Intent(ItsMe247.this, MainActivity.class);
                       ItsMe247.this.startActivity(funIntent);
                       //ItsMe247.this.finish();

                       break;

                   case SimpleGestureFilter.SWIPE_LEFT:  

                       Intent funIntent2 = new Intent(ItsMe247.this, Contact.class);
                       ItsMe247.this.startActivity(funIntent2);
                       //ItsMe247.this.finish();

                       break;

                   case SimpleGestureFilter.SWIPE_DOWN:  

                       break;

                   case SimpleGestureFilter.SWIPE_UP:   

                       break;                                               
                   } 

        }//end onSwipe method

      public void onDoubleTap() {

      }


}

I have all the menu buttons commented out (the buttons I'm trying to get to display above webview) until I finally get them to display through the xml. However, whenever I UNcomment the buttons and their listeners, the app crashes when trying to enter this activity.

LargeGlasses
  • 912
  • 10
  • 17
  • Try using `RelativeLayout` as parent layout instead of `LinearLayout` – Zombie Oct 13 '12 at 09:09
  • @BobbeHoddi that approach actually did not work. I've tried lots of different combinations using RelativeLayout with other layouts as well, but they did not work either. Thanks though! – LargeGlasses Oct 15 '12 at 19:37

1 Answers1

1

Your code isn't using your XML layout, you're creating your own WebView in code and setting that as the view so it bypasses your XML completely.

I've provided a few changes here that should make it work. Pay particular attention to the setContentView line and the following line, these are what use the XML layout. You may need to change the name of the layout (R.layout.whatever) and the webview id (R.id.webview). There may be a few parse errors from me putting it here, might have missed a closing bracket. I deleted much of your commented out code just to keep it simple.

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView( R.layout.xmlLayout );

    itsMeLogin = (WebView)findViewById( R.id.webview );

    detector = new SimpleGestureFilter(this,this);

    Toast.makeText(this, "Just Swipe To Exit", Toast.LENGTH_LONG).show();


    itsMeLogin.getSettings().setJavaScriptEnabled(true); // JavaScript enabled

    getWindow().requestFeature(Window.FEATURE_PROGRESS); // Show progress bar of page loading

    final Activity itsMeActivity = this;


    itsMeLogin.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress){

            // Activities and WebViews measure progress with different scales.
            // The progress meter will automatically disappear when we reach 100%
            itsMeActivity.setProgress(progress * 100);

        }

    });

    itsMeLogin.setWebViewClient(new WebViewClient(){

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){

            Toast.makeText(itsMeActivity, "Oh no! " + description, Toast.LENGTH_SHORT).show();

        }


    });

    itsMeLogin.loadUrl("http://www.google.com");
}

Here's my XML file from a similar layout as well, though yours will probably work with the edited code.

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:columnCount="3"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
>
<EditText
    android:ems="4"
    android:imeOptions="actionNext"
    android:inputType="number"
    android:layout_gravity="center_horizontal"
    android:maxLength="4"
    android:selectAllOnFocus="true"
/>
<EditText
    android:ems="4"
    android:imeOptions="actionDone"
    android:inputType="textCapCharacters|textNoSuggestions"
    android:layout_gravity="center_horizontal"
    android:maxLength="3"
    android:selectAllOnFocus="true"
/>
<Button android:id="@+id/submit"
/>
<WebView android:id="@+id/webview"
    android:layout_columnSpan="3"
    android:layout_gravity="fill"
    android:layout_height="0dp"
    android:layout_width="0dp"
/>
</GridLayout>
Khantahr
  • 8,156
  • 4
  • 37
  • 60
  • I'm trying your suggestion still, but it is not working so far. Although, I had to add tools:ignore="NewApi" in order for an error to disappear when trying to use GridLayout. Maybe that has something to do with it... – LargeGlasses Oct 15 '12 at 19:39
  • If you're developing for a version prior to API level 14, you'll need to use the compatibility library. See [this question](http://stackoverflow.com/questions/9126780/how-to-make-android-gridlayout-compatible-to-older-version) for how to do that. – Khantahr Oct 15 '12 at 19:42
  • Thanks. Any insight as to how to complete steps 2 and 3 in the accepted answer in your link? I added the GridLayout project to eclipse, but how do you "Make the project as library" and "Add this library project to your working project"?? – LargeGlasses Oct 15 '12 at 20:14
  • [This question](http://stackoverflow.com/questions/4085313/how-to-create-your-own-library-for-android-development-to-be-used-in-every-progr) should help with that. The second-to-last answer is most concise. – Khantahr Oct 15 '12 at 20:23
  • Ok, I'm getting closer. The console is giving me this error: [2012-10-15 14:37:20 - android-support-v7-gridlayout] Unable to resolve target 'android-7' and I've got a big red exclamation point next to the library project I imported, as well as next to my main project. – LargeGlasses Oct 15 '12 at 20:53
  • I think you have to download the Android 2.1 SDK Platform in your SDK manager to fix that. – Khantahr Oct 15 '12 at 21:10
  • That took away the exclamation points! Thanks! Now I'll see if I can get GridLayout to do what I need it to. I'll let you know. Oh, and do I have to add anything to my Manifest in order to use GridLayout? – LargeGlasses Oct 15 '12 at 21:32
  • It's still not working. I even copied and pasted your code to see if it would display correctly when ran in the emulator, and it did not. For other things in my app, i had to put into my manifest, and because of that i have to put tools:ignore="NewApi" into the definition of my GridLayout in xml. Could that be the issue?? – LargeGlasses Oct 15 '12 at 22:00
  • If you copy/paste my code you'll have to change match_parent to fill_parent for the lower API levels and add the library namespace to the GridLayout, though I don't think it would even run without doing those so maybe you already did. Can you put the code that displays the layout in the question? – Khantahr Oct 15 '12 at 22:26
  • Wait, so do I also need to do something in the java code in order for GridLayout to work? – LargeGlasses Oct 15 '12 at 22:39
  • No, I just want to see if there's something going on in your code because if you just straight copied my XML it should have worked. – Khantahr Oct 15 '12 at 22:40
  • Ok, I made sure everything was the same as your edits. The app runs, but still crashes when trying to enter the activity.... I really thought that would have solved it... :/ – LargeGlasses Oct 15 '12 at 23:44
  • Comment out everything between itsMeLogin = (WebView)findViewById( R.id.webview ); and itsMeLogin.loadUrl("http://www.google.com"); That should run and tell you if the layout works. – Khantahr Oct 15 '12 at 23:57
  • Ok, that took me to the activity, WITH buttons at top, but it immediately switched itself out of that activity and loaded a webview by itself. Looks like we're almost there! – LargeGlasses Oct 16 '12 at 00:00
  • It's something in your code doing that. Comment out everything except `super.onCreate(savedInstanceState); setContentView( R.layout.xmlLayout );` and you'll see the layout. The other problem is unrelated to your layout. – Khantahr Oct 16 '12 at 00:17
  • getWindow().requestFeature(Window.FEATURE_PROGRESS) was the reason it was crashing. I've got it to the point now where it shows my layout, but after about 8 seconds it says "Web page not available". I got it to stay on my layout by uncommenting the setWebViewclient that contains the shouldOverrideUrlLoading method. I'm not sure why it isn't loading my url. – LargeGlasses Oct 16 '12 at 00:23
  • Hey, it was actually just my emulator that needed to be shut down and restarted again! It works now!! I've searched for this solution for months!! Thank you so much for the help/solution!!! – LargeGlasses Oct 16 '12 at 00:53