Reputation:
So I tried converting the site I am working on to an android app using android studio
App was built successfully, no errors, opens when clicked but just stays static. I cannot interact with it.. It just stays on the main page, no interaction. cannot swipe up/down/left/right layout is not correct cannot click the search box the main site does adapt to different screen sizes
can you help me diagnose it?
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">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>
MainActivity.java
package tech.radhelper.radhelpertech;
import android.app.ListActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends ListActivity {
private WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://radhelper.tech/");
myWebView.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed() {
if(myWebView.canGoBack()) {
myWebView.goBack();
} else
super.onBackPressed();
}
}
AndroidManifest.xmml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tech.radhelper.radhelpertech">
<uses-permission android:name="android.permission.INTERNET"></uses-
permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Upvotes: 0
Views: 255
Reputation:
I got it to work by changing ListActivity to AppCompatActivity
and then changing the activity_main.xml
the code I use is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ListView>
</RelativeLayout>
I wrap the content instead of filling/match parent..
thanks to Abhinav Gupta for the help.. Cheers bai!
Upvotes: 1