【发布时间】:2020-10-07 10:39:39
【问题描述】:
我想使用 SwipeRefreshLayout 来替换数据, 但是当我这样做时
mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.refresh);
mSwipeRefreshLayout 为空。 代码示例:
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
private SwipeRefreshLayout mSwipeRefreshLayout ;
@Override
protected void onCreate(Bundle savedInstanceState) {
mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.refresh);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Toast.makeText(SpisokActivity.this, "Обновление", Toast.LENGTH_SHORT).show();
mSwipeRefreshLayout.setRefreshing(false);
}
});
所以,之后
mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.refresh) 我得到一个错误。我认为原因是 mSwipeRefreshLayout 有 null。
【问题讨论】:
标签: java android swiperefreshlayout