我正在使用TabLayouta 和 a 组合,ViewPager并且我已经为我的选项卡设置了自定义视图。当选择和取消选择选项卡时,一切都按预期工作(自定义视图根据所选/未选择的选项卡而更改)。
问题是在第一次启动时,永远不会调用 onTabSelected 方法。
这是我的活动:
setupViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
for (int i = 0; i < tabLayout.getTabCount(); i++) {
tabLayout.getTabAt(i).setCustomView(getViewAt(i));
}
tabLayout.addOnTabSelectedListener(this);
Run Code Online (Sandbox Code Playgroud)
这是setupViewPager和其他方法:
private void setupViewPager(ViewPager viewPager) {
MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getChildFragmentManager(), getContext(), startDate, endDate);
viewPager.setAdapter(adapter);
}
private View getViewAt(int i){
final Date currentDate = CalendarUtility.addDay(startDate, i);
View v = LayoutInflater.from(getContext()).inflate(R.layout.layout_custom_tab, null);
TextView day = (TextView) v.findViewById(R.id.day);
TextView num = (TextView) v.findViewById(R.id.num);
day.setText(CalendarUtility.getDayOfWeek(currentDate));
num.setText(CalendarUtility.getDayOfMonth(currentDate));
return v;
}
@Override
public void onTabSelected(TabLayout.Tab tab) …Run Code Online (Sandbox Code Playgroud) 我有用于发送通知的应用,我将这段代码用于待处理的意图
Intent myIntent = new Intent(getApplicationContext(),MainActivity.class);
myIntent.putExtra("link",Link);
PendingIntent intent2 =
PendingIntent.getActivity(getApplicationContext(),1,myIntent,
PendingIntent.FLAG_ONE_SHOT);
Run Code Online (Sandbox Code Playgroud)
并第一次很好地工作,但是我在每1分钟调用一次的方法中使用了这段代码。
问题在于link变量从一个变为另一个。
当我在中MainActivity找到数据时,仅找到最后一个链接,所有创建的通知都具有最后一个链接。
而且我不知道如何避免这种情况。
java.lang.RuntimeException:无法创建应用程序 com.android.tools.fd.runtime.BootstrapApplication:java.lang.IllegalStateException:java.lang.NoSuchFieldException:Landroid/content/res/MiuiResourcesImpl 类中没有字段 mAssets;('android.content.res.MiuiResourcesImpl' 的声明出现在 /system/framework/framework.jar) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5431) at android.app.ActivityThread.-wrap2(ActivityThread. java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1563) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6195) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os。ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764) 引起:java.lang.IllegalStateException:java.lang.NoSuchFieldException:没有字段massets类 Landroid/content/res/MiuiResourcesImpl; ('android.content.res.MiuiResourcesImpl' 的声明出现在 /system/framework/framework.jar 中)在 com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources(MonkeyPatcher.java:442) 在 com.android.tools .fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:308) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5428) ... 8 更多引起:java.lang.NoSuchFieldException:Landroid/content/res/MiuiResourcesImpl 类中没有字段 mAssets;('android.content.res.MiuiResourcesImpl' 的声明出现在 /system/framework/framework.jar 中)在 java.lang.Class.getDeclaredField(Native Method) at com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources( MonkeyPatcher.java:433) ... 11
有没有人可以帮助我?谢谢!
没有NestedScrollView可以使用,但是当我使用该滚动到无法使用RecyclerView的位置时
下面是xml代码;
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/co_ordinate_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_gray">
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_55"
android:fillViewport="true">
<LinearLayout
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img_resturant"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@drawable/products_offers"
android:scaleType="fitXY" />
<LinearLayout
android:id="@+id/llTransparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_20"
android:focusableInTouchMode="true"
android:orientation="vertical">
<TextView
android:id="@+id/tvRestaurantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/dimen_15"
android:textColor="@color/white"
android:textSize="@dimen/sp_20" />
<TextView
android:id="@+id/tvAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toRightOf="@+id/ivTime"
android:textColor="@color/white"
android:textSize="@dimen/sp_14" />
<TextView
android:id="@+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:textColor="@color/white"
android:textSize="@dimen/sp_14" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="@dimen/_20sdp"
android:layout_marginRight="@dimen/_20sdp"
android:layout_marginTop="@dimen/_10sdp"
android:background="@color/white" />
<LinearLayout
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud)