android - impossible to scroll the screen with preference screen inside a Tabhost -


i'm creating first app android had found problems in scrolling preferencescreen inside tabhost. problem related fact than, if nestedscrollview present, tab's content doesn't scroll.

if take @ visual editor provided android studio can notice 2 gridlayouts (with ids tab1/tab2) have size equal zero. if assign them big height scrolling works (but of course have lot of blank space).

i tried change size of gridlayout programmatically had no luck.

someone know how can fix problem?

this activitysetting.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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="com.example.kia.securelock.locksettingsactivity">  <include layout="@layout/toolbar"     android:id="@+id/settings_toolbar"     android:layout_height="wrap_content"     android:layout_width="0dp"     app:layout_constraintright_torightof="parent"     app:layout_constraintleft_toleftof="parent"     app:layout_constrainttop_totopof="parent"     app:layout_constrainthorizontal_bias="0.0" />  <tabhost xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@android:id/tabhost"     android:layout_width="0dp"     android:layout_height="495dp"     android:layout_marginend="8dp"     android:layout_marginleft="8dp"     android:layout_marginright="8dp"     android:layout_marginstart="8dp"     android:layout_margintop="8dp"     app:layout_constrainthorizontal_bias="0.0"     app:layout_constraintleft_toleftof="parent"     app:layout_constraintright_torightof="parent"     app:layout_constrainttop_tobottomof="@+id/settings_toolbar">      <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">          <tabwidget             android:id="@android:id/tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content"></tabwidget>          <!--<include layout="@layout/settings_options" />-->         <android.support.v4.widget.nestedscrollview             android:layout_width="match_parent"             android:layout_height="match_parent"             android:fillviewport="true"             android:scrollbars="vertical"              app:layout_behavior="@string/appbar_scrolling_view_behavior">              <framelayout xmlns:android="http://schemas.android.com/apk/res/android"                 android:id="@android:id/tabcontent"                 android:layout_width="match_parent"                 android:layout_height="1000dip"                 android:layout_gravity="top">                  <gridlayout                     android:id="@+id/tab1"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:columncount="2"                     android:rowcount="10"></gridlayout>                  <gridlayout xmlns:android="http://schemas.android.com/apk/res/android"                     android:id="@+id/tab2"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:columncount="2"                     android:rowcount="10"></gridlayout>               </framelayout>         </android.support.v4.widget.nestedscrollview>     </linearlayout> </tabhost> 

preference_tab1.xml

<!--android:key-> used save key-value pair used system save setting in     default sharedpreferences file. no interaction sharedpreferencesfile required     (the system saves user's changes automatically) --> <preferencecategory     android:title="@string/alarm_triggers"     android:key="pref_key_alarm_triggers">      <switchpreference         android:key="pref_key_alarm_trigger_proximity_switch"         android:title="@string/alarm_trigger_proximity_title"         android:summary="@string/alarm_trigger_proximity_summary"         android:defaultvalue="false"         android:enabled="true"/>      <switchpreference         android:key="pref_key_alarm_trigger_accelerometer_switch"         android:title="@string/alarm_trigger_accelerometer_title"         android:summary="@string/alarm_trigger_accelerometer_summary"         android:defaultvalue="false"         android:enabled="true"/>       <switchpreference         android:key="pref_key_alarm_trigger_charging_switch"         android:title="@string/alarm_trigger_charging_title"         android:summary="@string/alarm_trigger_charging_summary"         android:defaultvalue="false"         android:enabled="true"/> </preferencecategory>   <listpreference     android:defaultvalue="5"     android:key="pref_key_alarm_trigger_time_to_ring"     android:title="@string/alarm_trigger_time_to_ring_title"     android:summary="@string/alarm_trigger_time_to_ring_summary"     android:entries="@array/alarm_trigger_time_to_ring"     android:entryvalues="@array/alarm_trigger_time_to_ring" />    </preferencescreen> 

and related activity

package com.example.kia.securelock;   import android.app.fragmentmanager; import android.app.fragmenttransaction; import android.content.intent; import android.os.bundle; import android.preference.preferencemanager; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.util.log; import android.view.view; import android.widget.framelayout; import android.widget.gridlayout; import android.widget.imageview; import android.widget.tabhost;   public class locksettingsactivity extends appcompatactivity { static final string tag = "sl.locksettingsactivity"; protected string tag1, tag2;  private settingsfragmenttab2 fragment2; private static tabhost tabhost;  private boolean enablegps; private int currenttab;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      intent intent = getintent();     bundle bundle = intent.getextras();     if(bundle != null) {         enablegps = intent.getbooleanextra("enablegps", false);     }      setcontentview(r.layout.activity_settings);      inituppertoolbar();     inittabs();     connectfragments(); }  @override protected void onresume(){     super.onresume();      //enable od disable gps settings     fragment2 = (settingsfragmenttab2) getfragmentmanager().findfragmentbytag(tag2);     fragment2.findpreference("pref_key_alarm_gps").setenabled(enablegps);      tabhost.setcurrenttab(currenttab);   }   @override protected void onstart(){     super.onstart();     log.i(tag, "onstart");   }   @override protected void onsaveinstancestate(bundle outstate) {     super.onsaveinstancestate(outstate);     log.i(tag, "onsaveinstancestate");      currenttab =tabhost.getcurrenttab();     outstate.putint("current_tab", tabhost.getcurrenttab());      outstate.putstring("tag1", tag1);     outstate.putstring("tag2", tag2);      outstate.putboolean("enable_gps", enablegps); }  protected void onrestoreinstancestate(bundle savedinstancestate) {     super.onrestoreinstancestate(savedinstancestate);     log.i(tag, "onrestoreinstancestate , saved state " +             (savedinstancestate == null ? "null" : "not null"));      currenttab = savedinstancestate.getint("current_tab");      tag1 = savedinstancestate.getstring("tag1", null);     tag2 = savedinstancestate.getstring("tag2", null);      enablegps = savedinstancestate.getboolean("enable_gps"); }  protected void inituppertoolbar(){     toolbar uppertoolbar;     imageview settingsbutton, homebutton;      uppertoolbar= (toolbar) findviewbyid(r.id.settings_toolbar);     setsupportactionbar(uppertoolbar);      //remove title upper toolbar     //setdisplayshowtitleenabled() may throw 'java.lang.nullpointerexception'      try {         getsupportactionbar().setdisplayshowtitleenabled(false);     }catch (java.lang.nullpointerexception e){         log.i(tag, "java.lang.nullpointerexception");     }      settingsbutton = (imageview) findviewbyid(r.id.settings_button);     homebutton = (imageview) findviewbyid(r.id.home_button);     settingsbutton.setvisibility(view.invisible);     homebutton.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             finish();         }     }); }   protected void inittabs() {         tabhost = (tabhost) findviewbyid(android.r.id.tabhost);         tabhost.setup();          final framelayout tabcontent = tabhost.gettabcontentview();          // ensure tab content childs not visible @ startup.         (int index = 0; index < tabcontent.getchildcount(); index++) {             tabcontent.getchildat(index).setvisibility(view.gone);         }          tabhost.tabspec tabspec1 = tabhost.newtabspec("tab1");         tabhost.tabspec tabspec2 = tabhost.newtabspec("tab2");          //set tab's content (from xml)         tabspec1.setcontent(r.id.tab1);         tabspec2.setcontent(r.id.tab2);          //set text displayed in tab         tabspec1.setindicator("allarm settings");         tabspec2.setindicator("messages , notifications");         //show tab         tabhost.addtab(tabspec1);         tabhost.addtab(tabspec2); }   private void connectfragments() {     fragmenttransaction fragmenttransaction;     fragmentmanager fragmentmanager = getfragmentmanager();      settingsfragmenttab1 fragment1 = new settingsfragmenttab1();     fragment2 = new settingsfragmenttab2();      fragmenttransaction = fragmentmanager.begintransaction();     fragmenttransaction.replace(r.id.tab1, fragment1, "tab1tag");     fragmenttransaction.replace(r.id.tab2, fragment2, "tab2tag");     fragmenttransaction.commit();     getsupportfragmentmanager().executependingtransactions();      tag1 = fragment1.gettag();     tag2 = fragment2.gettag();      //the system sets default values if method has never been called in past     // (or key_has_set_default_values in default value shared preferences_tab1 file false).     preferencemanager.setdefaultvalues(this, r.xml.preferences_tab1, false);     preferencemanager.setdefaultvalues(this, r.xml.preferences_tab2, false); } 

}


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -