java - My Second Activity [TabLayout] Not Supporting on all other device -
i beginner of android development.i planed create application helps education seeker of country.at posting time have created 2 activity. first activity created listview. , second activity created tablayout contains 3 fragments. when launched app on lollipop device,all activity working fine.but when launched on marshmallow device,first activity working when clicked on other list item,my apps getting closed automatically.but why??? here important information understood easily.
build.gradle
apply plugin: 'com.android.application' android { compilesdkversion 25 buildtoolsversion "24.0.2" defaultconfig { applicationid "waystoprogram.mcquniversityadmission" minsdkversion 10 targetsdkversion 25 versioncode 1 versionname "1.0" testinstrumentationrunner "android.support.test.runner.androidjunitrunner" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(include: ['*.jar'], dir: 'libs') androidtestcompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.android.support:support-v4:25.0.0' compile 'com.android.support:design:25.0.0' testcompile 'junit:junit:4.12' compile 'com.android.support:design:25.0.0' compile 'com.android.support:support-v4:25.0.0' }
secondactivity.java
package waystoprogram.mcquniversityadmission; import android.os.bundle; import android.support.design.widget.tablayout; import android.support.v4.app.fragmentactivity; import android.support.v4.view.viewpager; class secondactivity extends fragmentactivity { viewpager viewpager; tablayout tablayout; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.second_activity); viewpager = (viewpager) findviewbyid(r.id.viewpager); tablayout = (tablayout) findviewbyid(r.id.swiptab); tablayout.addtab(tablayout.newtab()); tablayout.addtab(tablayout.newtab()); tablayout.addtab(tablayout.newtab()); viewpager.setadapter(new viewpageradapter(getsupportfragmentmanager())); tablayout.setupwithviewpager(viewpager); tablayout.addontabselectedlistener(new tablayout.ontabselectedlistener() { @override public void ontabselected(tablayout.tab tab) { viewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(tablayout.tab tab) { viewpager.setcurrentitem(tab.getposition()); } @override public void ontabreselected(tablayout.tab tab) { viewpager.setcurrentitem(tab.getposition()); } }); } }
viewpageradapter.java
package waystoprogram.mcquniversityadmission; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentstatepageradapter; /** * created that's enam on 11/1/2016. */ public class viewpageradapter extends fragmentstatepageradapter { private string[] tabtitles = new string[]{"science", "commerce", "rc"}; public viewpageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int position) { if(position==0){ return new sciencedivision(); } if(position==1){ return new commercedivision(); } if(position==2){ return new sciencedivision(); } return null; } @override public int getcount() { return 3; } @override public charsequence getpagetitle(int position) { return tabtitles[position]; } }
second_acitvity.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xml:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/secondactivity"> <android.support.design.widget.tablayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/swiptab" app:tabindicatorcolor="#ff0066e2" app:tabtextcolor="@color/colorprimarydark" > </android.support.design.widget.tablayout> <android.support.v4.view.viewpager android:layout_width="match_parent" android:id="@+id/viewpager" android:layout_height="match_parent" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_below="@+id/swiptab"> </android.support.v4.view.viewpager> </relativelayout>
- sdk-platform
please me anyone.
Comments
Post a Comment