我的代碼
@Override
public void onBindViewHolder(ViewHolder _holder, final int _position) {
View _view = _holder.itemView;
final LinearLayout linear1 = _view.findViewById(R.id.linear1);
final LinearLayout linear2 = _view.findViewById(R.id.linear2);
final LinearLayout linear4 = _view.findViewById(R.id.linear4);
final androidx.cardview.widget.CardView cardview2 = _view.findViewById(R.id.cardview2);
final LinearLayout linear3 = _view.findViewById(R.id.linear3);
final LinearLayout linear7 = _view.findViewById(R.id.linear7);
final ImageView imageview1 = _view.findViewById(R.id.imageview1);
final TextView textview1 = _view.findViewById(R.id.textview1);
final TextView textview2 = _view.findViewById(R.id.textview2);
final LinearLayout linear5 = _view.findViewById(R.id.linear5);
final TextView textview3 = _view.findViewById(R.id.textview3);
final TextView textview4 = _view.findViewById(R.id.textview4);
final LinearLayout linear10 = _view.findViewById(R.id.linear10);
final ImageView imageview3 = _view.findViewById(R.id.imageview3);
duration = Double.parseDouble(videos.get((int)_position).get("videoDuration").toString());
videoDuration = stringForTime((int)duration);
textview1.setText(videoDuration);
path = videos.get((int)_position).get("videoPath").toString();
//using cardview programmatically inside recyclerview .
androidx.cardview.widget.CardView cardview1 = new androidx.cardview.widget.CardView(FolderListFragmentActivity.this);
cardview1.setCardElevation(0);
cardview1.setRadius(10);
ViewGroup imageParent = ((ViewGroup)imageview1.getParent()); imageParent.removeView(imageview1);
cardview1.addView(imageview1);
imageParent.addView(cardview1);
textview2.setText(Uri.parse(path).getLastPathSegment());
size = Double.parseDouble(videos.get((int)_position).get("videoSize").toString());
humanReadableSize = bytesIntoHumanReadable((long)size);
textview3.setText(humanReadableSize);
com.bumptech.glide.Glide.with(getContext().getApplicationContext())
.load(path)
.into(imageview1);
textview4.setText(videos.get((int)_position).get("formattedDate").toString());
}
錯誤是
androidx.cardview.widget.CardView cardview1 = new androidx.cardview.widget.CardView(FolderListFragmentActivity.this);
建構式 CardView(FolderListFragmentActivity) 未定義
uj5u.com熱心網友回復:
你是在一個片段,一個活動中,還是兩者都沒有?
如果您在活動中,代碼應該可以作業。
如果您在片段中,請嘗試:
androidx.cardview.widget.CardView cardview1 = new androidx.cardview.widget.CardView(FolderListFragmentActivity.this.getContext());
如果你都不在……
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/522120.html
標籤:爪哇安卓安卓布局
上一篇:無法向布局添加值
下一篇:在空obj參考上呼叫虛擬方法'voidandroidx.viewpager2.widget.ViewPager2.setAdapter(androidx.recyclerview.widge
