I am trying to implement a WebView in one one of my xml files in my android studios mobile app project. What I am trying to do is have a few buttons that will navigate through different pages that are local to the app, and have a webpage beneath those buttons. However, the webview keeps taking up the entire screen space and the buttons that I created can no longer be seen. For reference, here is the xml.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#ffffff"
tools:context=".GetInvolved" >
<Button
android:id="#+id/homeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="51dp"
android:adjustViewBounds="true"
android:background="#android:color/black"
android:clickable="false"
android:onClick="goHome"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="#+id/webView"
android:layout_width="408dp"
android:layout_height="572dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homeButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
And here is how I'm loading the webview
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
view = findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient() {
#Override
public void onLoadResource(WebView webView, String url) {
try {
// remove the nav bar and the footer from each loaded page.
view.loadUrl("javascript:(window.onload = function() { " +
"})()");
} catch (Exception e) {
e.printStackTrace();
}
}
});
view.loadUrl("https://www.google.com/");
}
I have tried several different Stack Overflow posts like this one Webview is taking fullscreen in android but I could not get it to work. Any help is appreciated, thank you.
You can add app:layout_constraintHorizontal_bias and app:layout_constraintVertical_bias in the Webview tag
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#ffffff"
>
<Button
android:id="#+id/homeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="51dp"
android:adjustViewBounds="true"
android:background="#android:color/black"
android:clickable="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="#+id/webView"
android:layout_width="408dp"
android:layout_height="572dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homeButton"
app:layout_constraintVertical_bias="0.037" />
</androidx.constraintlayout.widget.ConstraintLayout>
Related
I wanted to refresh my fragment with SwipeToRefresh widget.
This is my XML Code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="#drawable/gradient_drawable"
android:padding="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Fragment_1">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progress"
android:layout_width="76dp"
android:layout_height="64dp"
android:elevation="10dp"
android:foregroundGravity="center"
android:indeterminateTint="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.84" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="5dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
and this is my JAVA code
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_1, container, false);
newconfig= getResources().getConfiguration();
db=new DBHandler(getActivity());
swipeRefreshLayout=view.findViewById(R.id.swipe);
recyclerView=view.findViewById(R.id.listview);
progressBar=view.findViewById(R.id.progress);
if(book.size()==0) {
book = db.readCourses();
}
progressBar.setVisibility(View.GONE);
BookFragAdapter adapter = new BookFragAdapter(Fragment_land1.this,book);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(),RecyclerView.VERTICAL,false));
recyclerView.setAdapter(adapter);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
this.onRefresh();
getFragmentManager().beginTransaction().detach(Fragment_land1.this).attach(Fragment_land1.this).commit();
swipeRefreshLayout.setRefreshing(false);
}
});
return view;
}
When I try to refresh it doesn't refresh and the widget doesn't stops after 250ms. I assume that the code inside onRefreshListener is not actually executing therefore the next line is ignored. I don't know how change it with. I surfed in Stackoverflow and Developer.android none of the answers solved my problem. Can anyone help me?
first check that you have added dependencies in build.gradle file
i.e implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
Secondly swipe to refresh layout tag should start from start instead of fragment
for eg :
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_drawable"
android:padding="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Fragment_1">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progress"
android:layout_width="76dp"
android:layout_height="64dp"
android:elevation="10dp"
android:foregroundGravity="center"
android:indeterminateTint="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.84" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="5dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
third then write swipeRefreshLayout.setOnRefreshListener code in java file
package com.example.appthree;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String Htmlurl = "file://android_assets/index.html";
WebView view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(Htmlurl);
}
}
This is my MainActivity.java file. I want to rander html file on app which is inside the assets folder. But I'm getting this error ->
error: cannot find symbol
WebView view = (WebView) this.findViewById(R.id.webView);
^
symbol: variable webView
location: class id
see screenshot (https://prnt.sc/yx65CzqLDBmk)
Updated____
this is my activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.043" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="193dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
You need to add the WebView inside the ConstraintLayout as Halil Ozel's code. Something like this
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.043" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="193dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
You need to add internet permission in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Make sure that your id of webView component into activity_main.xml is webView.
WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I'm currently developing an application on Android Studio, and I've an issue with a scrollview. I create buttons dynamically (with a number of buttons equal to the number of buttons in my Database), but I can't scroll to the bottom of the page and see every button. I don't know if this issue is caused by the ScrollView or by the LinearLayout inside the ScrollView. Here is the XML and the Java code for it :
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="#+id/layoutgroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_list"
tools:context=".GroupList">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="134dp"
android:fontFamily="#font/cartoon"
android:text="Artists"
android:textColor="#FFFFFF"
android:textSize="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/back"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/back"
android:layout_width="0dp"
android:layout_height="68dp"
android:layout_marginStart="11dp"
android:layout_marginEnd="67dp"
app:layout_constraintEnd_toStartOf="#+id/textView3"
app:layout_constraintHorizontal_bias="0.135"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="#drawable/back2" />
<ScrollView
android:id="#+id/listG"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="1dp"
android:fillViewport="true"
android:layout_marginTop="10dp"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/back">
<LinearLayout
android:id="#+id/layoutG"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Java (the loop that creates buttons dynamically) :
while(db.selectArtist(i).size()>0){
List<String> data = db.selectArtist(i);
Log.i("Artiste",String.valueOf(data));
Button bouton = new Button(getApplicationContext());
bouton.setX(160);
bouton.setY(1 * i + 60);
bouton.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
layoutG.addView(bouton,LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
bouton.setText(data.get(0));
bouton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent start = new Intent(getApplicationContext(), start.class);
start.putExtra("NomArtiste", String.valueOf(bouton.getText()));
start.putExtra("IdArtiste", String.valueOf(data.get(1)));
startActivity(start);
finish();
}
});
i=i+1;
listB.add(i + 1);
}
Here is the result
image
Thanks for your help, it's my first post here, and I'm new in coding in Java!
You need to wrap the whole layout with the scroll view as wrapping just the linearlayout (in context of your code) will make the layout scrollable but it wont include its child views fully.
consider using the following layout: (tweak some values to your comfort)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="#+id/your-desired-view-name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginTop="10dp"
android:background="your-desired-background-here"
android:fillViewport="true"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/back"
tools:context="your-desired-context-here">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="134dp"
android:fontFamily="#font/cartoon"
android:text="Artists"
android:textColor="#FFFFFF"
android:textSize="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/back"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/back"
android:layout_width="0dp"
android:layout_height="68dp"
android:layout_marginStart="11dp"
android:layout_marginEnd="67dp"
app:layout_constraintEnd_toStartOf="#+id/textView3"
app:layout_constraintHorizontal_bias="0.135"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="#drawable/back2" />
<LinearLayout
android:id="#+id/layoutG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I am new to android programming and I do not know many things yet. What I am trying to achieve here is something like this. If the user does not have internet connection the ads dont show up or if the ads for some reason does not load then the ads dont show up. But the layout does remains the same meaning the ad space is left empty. What I did was warp the ad view in inside of a Relative Layout and then created a function which checks if the ads are loaded or not then changes the visibility of the layout, this seems to work and solve the blank space issues when ads does not load. But I think that this is not best way to do this and there must be a better way.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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"
tools:context="com.example.admobTest.MainActivity"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/btnExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="#string/btnExit"
ads:layout_constraintBaseline_toBaselineOf="#+id/btnViewBuildProp"
ads:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/btnViewBuildProp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#string/btnViewBuildProp"
ads:layout_constraintBottom_toTopOf="#+id/relativeAdsLayout"
ads:layout_constraintStart_toStartOf="parent" />
/>
<TextView
android:id="#+id/txvStatus"
android:layout_width="368dp"
android:layout_height="0dp"
android:text="TextView"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
<TextView
android:id="#+id/txvDeviceInfo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
ads:layout_constraintBottom_toTopOf="#+id/btnViewBuildProp"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toBottomOf="#+id/txvStatus" />
<RelativeLayout
android:id="#+id/relativeAdsLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="gone"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toBottomOf="#+id/btnExit">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="#string/adSize"
ads:adUnitId="#string/adUnitId"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="457dp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java only relevant bits
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showAds(true); // this displays the ads
}
private void showAds(Boolean doShowAds) {
RelativeLayout relativeAdsLayout = findViewById(R.id.relativeAdsLayout);
if (doShowAds.equals(true)) {
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
relativeAdsLayout.setVisibility(View.VISIBLE);
} else if (doShowAds.equals(false)) {
relativeAdsLayout.setVisibility(View.GONE);
}
} //end showAds
} //end class
Don't add the AdView at all if the user has no internet connection.
Also an ad request should be avoided, if you know the user has no proper internet connection.
If the ad request fails you could remove the AdView from the Layout or try an other add request as often as you want.
You might also add some progress or an other background view (or image, progress etc.), wile the ad loads or if the user has no internet
I have a swipe to refresh view and a listview within in the swipe to refresh view
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
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:id="#+id/refreshView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No data available"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:textSize="20sp"
android:visibility="gone"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</TextView>
<ListView
android:id="#+id/ArrayList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toBottomOf="parent">
</ListView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
I can scroll down the list but when i want to go back up, the swipe to refresh kicks in and I got to be able to view the entire list, any recommendations ??
and this is the implementation for the listener
srl = (SwipeRefreshLayout) view.findViewById(R.id.refreshView);
srl.setOnRefreshListener(srfListener());
function for listener
protected SwipeRefreshLayout.OnRefreshListener srfListener() {
return new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
update();
}
};
}
and update function
#Override
protected void update() {
HomeActivity.getInstance().onResume();
srl.setRefreshing(false);
}
Use like this
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/ArrayList"
android:scrollbars="vertical"
android:paddingBottom="85dp"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v4.widget.SwipeRefreshLayout
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:id="#+id/refreshView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/ArrayList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toBottomOf="parent">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
Swipe refresh view should only wrap around the listview/recyclerViews .....not around the parent view
Try this:
srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
{
#Override
public void onRefresh()
{
update();
}
});
instead of this:
protected SwipeRefreshLayout.OnRefreshListener srfListener() {
return new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
update();
}
};
}
Xml:
Take Linear layout instead of ConstraintLayout.