我在片段中的 SwipeRefreshLayout 中有一个 recyclerview 。我已经实现了 AsyncTask 来为 recyclerview 获取数据。问题是 SwipeRefreshLayout 根本不显示,因此数据不会填充到 recyclerview 中。我对 Activity 做了同样的事情,它工作得很好,但不是片段。有人可以指导我我做错了什么吗?这是片段的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".FeatureFragment">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我在片段类中所做的。
public class FeaturedFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private RecyclerView mRecyclerView;
private SwipeRefreshLayout mSwipeLayout;
public FeaturedFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view …
Run Code Online (Sandbox Code Playgroud) android android-asynctask swiperefreshlayout android-recyclerview
我试图将 onClickListener 添加到 RecyclerView 内的一个按钮,该按钮复制一个字符串,但它说 getSystemService(CLIPBOARD_SERVICE) 不可用。
public void onBindViewHolder(ViewHolder holder, int position) {
holder.title.setText(cardItems.get(position).title);
holder.content.setText(cardItems.get(position).content);
holder.copyButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
String text;
text = EditText.getText().toString();
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getApplicationContext(), "Text Copied", Toast.LENGTH_SHORT).show();
}
});
}
Run Code Online (Sandbox Code Playgroud) java android android-context android-adapter clipboardmanager
有没有办法在不变形的情况下调整位图大小,使其不超过 720*1280 ?较小的高度和宽度完全没问题(在较小宽度或高度的情况下空白画布很好)我尝试了这个/sf/answers/1080891801/,但它给出了扭曲的图像。有人能提出更好的解决方案吗?
我想添加一个按钮,该按钮将从卡片视图内的不可编辑文本视图中复制文本。我可以为此使用剪贴板管理器吗?