更新:
当片段中的recyclerview中实际上没有显示任何内容时,我想显示“列表中没有项目”。这就是我想要的:
在我的片段中:
// Drawing the square
var width = 0,
height = 0,
widthValue = document.getElementById('wid'),
heightValue = document.getElementById('hgt');
widthValue.value = width;
heightValue.value = height;
widthValue.addEventListener("change", function () {
width = this.value;
}, false);
heightValue.addEventListener("change", function () {
height = this.value;
}, false);
function draw() {
context.clearRect(0, 0, canvas.width, canvas.height);
context.rect(0, 0, width, height);
context.fillStyle = "#EA7B00";
context.fill();
}
在我的片段的java文件中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f0f0"
android:animateLayoutChanges="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/assigned_recycler"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp"
android:background="#f0f0f0"
android:animationCache="true"
android:animateLayoutChanges="false" />
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"
android:text="@string/no_data_available" />
我在这里错过了什么吗?
还需要对我的布局代码和颜色做些什么吗?
答案 0 :(得分:2)
请在onCreateView
,
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_assigned_orders, container, false);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.assigned_recycler);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this.getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Assigned");
emptyViewText = (TextView)rootView.findViewById(R.id.empty_view);
if(orderService.getAssignedOrders().size() != 0) {
mRecyclerView.setVisibility(View.VISIBLE);
emptyViewText.setVisibility(View.GONE);
mAdapter = new AssignedOrdersListAdapter(orderService.getAssignedOrders());
mAdapter.setManager(getFragmentManager());
mRecyclerView.setAdapter(mAdapter);
} else {
mRecyclerView.setVisibility(View.GONE);
emptyViewText.setVisibility(View.VISIBLE);
}
new LegDistanceTask().execute("");
return rootView;
}
上述代码将检查从服务接收的列表是否为空,并相应地显示组件。
您应该检查列表大小以确定,而不是适配器计数。