我创建了一个小应用程序,它解析html文档并将其显示在ViewPager
中包含的ListView中。到目前为止一切顺利,一切正常 - 至少在我的手机上。
现在我已经让一些人尝试为我测试应用程序,并且最重要的是它似乎对我来说也是如此。然而,有些人(顺便说一下只有三星电话用户)有以下问题:
(出于隐私原因,内容模糊)
我从其中一个人那里借了一部电话并将它连接到我的笔记本电脑上,这样我就可以查看日志了。由于所有try / catch子句都应打印出异常并且日志中没有任何内容,因此我尝试稍微更改XML文件,但没有成功。
使用ViewPager的活动:
<android.support.design.widget.CoordinatorLayout 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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="de.fuchstim.vertretungsplan.Table">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:layout_gravity="bottom|right"
app:srcCompat="@drawable/reload_arrow_white" />
</android.support.design.widget.CoordinatorLayout>
ViewPager片段:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Heute (25.10.16)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.DialogWindowTitle"
android:textAlignment="center" />
<GridLayout android:layout_gravity="start"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/grade_desc"
android:layout_height="wrap_content"
android:text="Klasse"
android:layout_row="0"
android:layout_column="0"
android:layout_width="0dp"
android:textSize="14sp"
android:layout_columnWeight="30"
android:paddingStart="10dp" />
<TextView
android:text="Stunde"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/hour_desc"
android:layout_row="0"
android:layout_column="1"
android:layout_columnWeight="17.5"/>
<TextView
android:text="Lehrer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/teacher_desc"
android:layout_row="0"
android:layout_column="3"
android:layout_columnWeight="17.5"/>
<TextView
android:text="Kurs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/course_desc"
android:layout_row="0"
android:layout_column="2"
android:layout_columnWeight="17.5"/>
<TextView
android:text="Raum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/room_desc"
android:layout_row="0"
android:layout_column="4"
android:layout_columnWeight="17.5"/>
</GridLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:id="@+id/listView" />
</LinearLayout>
ListView项目:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:id="@+id/grade"
android:layout_height="wrap_content"
android:text="Klasse"
android:layout_row="0"
android:layout_column="0"
android:layout_width="0dp"
android:textSize="14sp"
android:layout_columnWeight="30"
android:paddingStart="10dp" />
<TextView
android:text="Stunde"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/hour"
android:layout_row="0"
android:layout_column="1"
android:layout_columnWeight="17.5"/>
<TextView
android:text="Lehrer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/teacher"
android:layout_row="0"
android:layout_column="3"
android:layout_columnWeight="17.5"/>
<TextView
android:text="Kurs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/course"
android:layout_row="0"
android:layout_column="2"
android:layout_columnWeight="17.5"/>
<TextView
android:text="Raum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/room"
android:layout_row="0"
android:layout_column="4"
android:layout_columnWeight="17.5"/>
</GridLayout>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:maxLines="1"
android:text="Description"
android:textSize="12sp"
android:layout_row="1"
android:layout_column="0"
android:gravity="left"
android:paddingTop="5dp"
android:paddingStart="10dp"
android:paddingBottom="5dp" />
</LinearLayout>
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if(position==0)
return TodayTableFragment.newInstance(position + 1);
if(position==1)
return TmrwTableFragment.newInstance(position + 1);
else
return TodayTableFragment.newInstance(position + 1);
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "today";
case 1:
return "tomorrow";
}
return null;
}
}
public static class TodayTableFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section number";
public TodayTableFragment() {
}
public static TodayTableFragment newInstance(int sectionNumber) {
TodayTableFragment fragment = new TodayTableFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER,sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.list,container,false);
todayTitle = (TextView) rootView.findViewById(R.id.title);
String[] tmp = new String[tableData[0].length+1];
ListView listView = (ListView)rootView.findViewById(R.id.listView);
todayListAdapter = new TodayListAdapter(getActivity(),R.layout.list_item,tmp);
listView.setAdapter(todayListAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if(!tableData[0][i][6].isEmpty()) {
Snackbar.make(view, "Vertretungs-Text:\n" + tableData[0][i][6], Snackbar.LENGTH_LONG).show();
} else {
Snackbar.make(view,"Keine weiteren Informationen vorhanden",Snackbar.LENGTH_LONG).show();
}
}
});
todayTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(getView(),addInfo[2],Snackbar.LENGTH_LONG).show();
}
});
todayTitle.setText(addInfo[0]);
return rootView;
}
}
public static class TodayListAdapter extends ArrayAdapter<String> {
public TodayListAdapter(Context context, int textViewResourceId) {
super(context,textViewResourceId);
}
public TodayListAdapter(Context context, int resource, String[] items) {
super(context,resource,items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.list_item, null);
}
String p = getItem(position);
if(p==null) {
TextView grade = (TextView) v.findViewById(R.id.grade);
TextView hour = (TextView) v.findViewById(R.id.hour);
TextView course = (TextView) v.findViewById(R.id.course);
TextView teacher = (TextView) v.findViewById(R.id.teacher);
TextView room = (TextView) v.findViewById(R.id.room);
TextView description = (TextView) v.findViewById(R.id.description);
try {
grade.setText(tableData[0][position][0]);
hour.setText(tableData[0][position][1]);
course.setText(tableData[0][position][2]);
teacher.setText(tableData[0][position][3]);
room.setText(tableData[0][position][4]);
description.setText(tableData[0][position][5]);
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
return v;
}
}
return v;
}
}
有没有人遇到过类似的问题?你怎么修好它的?或者我在某个地方犯了错误?
提前致谢^。^
我发现如果我删除columnWeight选项并将宽度设置为固定大小,它可以正常工作。如何在不删除columnWeight选项的情况下实现这一目标?
我已将GridLayout更改为LinearLayout,它现在似乎正在运行
答案 0 :(得分:0)
在getItem()
中,您返回TodayTableFragment.newInstance(position + 1)
两次。您不能这样做。也可以getCount
方法返回2.在您的情况下,它应该是3.