错误如图,代码没有错误提示,可以显示单页模式时的新闻标题,点击标题跳转到新闻内容界面的时候崩溃。双页模式直接崩溃。
多方检索之后尝试了如下方法最终解决:
1.clean project
2.更改原代码中xml文件中id相同的控件,使其id不相同。写代码时尽量避免控件id相同
1和2之间没有前后关系,只是因为同时尝试了两种方法不确定是哪个起了作用所以一起写出来了
例:
news_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/news_title_item"// 原代码id是news_title
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingRight="10dp"
android:paddingBottom="15dp"
android:textSize="18sp">
</TextView>
我同时改了news_content_frag.xml中的
<TextView
android:id="@+id/news_contents"// 原文是news_content
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="15dp"
android:textSize="18sp" />
不确定可以把一样的都改一遍
最终结果如下图