public class MainListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int MENU_ITEM_VIEW_TYPE = 0;
private static final int UNIFIED_NATIVE_AD_VIEW_TYPE = 1;
private final Context mContext;
private final ArrayList<Object> arrayList;
public MainListAdapter(Context context, ArrayList<Object> arrayList) {
this.mContext = context;
this.arrayList = arrayList;
}
public static class MainAdapterViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView duration;
Chip size;
RelativeLayout path;
ImageView thumbnail;
public MainAdapterViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
duration = itemView.findViewById(R.id.duration);
size = itemView.findViewById(R.id.file_size);
path = itemView.findViewById(R.id.item_path);
thumbnail = itemView.findViewById(R.id.thumbnail);
}
}
@Override
public int getItemCount() {
return arrayList.size();
}
@Override
public int getItemViewType(int position) {
Object recyclerViewItem = arrayList.get(position);
if (recyclerViewItem instanceof UnifiedNativeAd) {
return UNIFIED_NATIVE_AD_VIEW_TYPE;
}
return MENU_ITEM_VIEW_TYPE;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
switch (viewType) {
case UNIFIED_NATIVE_AD_VIEW_TYPE:
View unifiedNativeLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.ad_unified, viewGroup, false);
return new UnifiedNativeAdViewHolder(unifiedNativeLayoutView);
case MENU_ITEM_VIEW_TYPE:
default:
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_video_list, viewGroup, false);
return new MainAdapterViewHolder(view);
}
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
int viewType = getItemViewType(position);
switch (viewType) {
case UNIFIED_NATIVE_AD_VIEW_TYPE:
UnifiedNativeAd nativeAd = (UnifiedNativeAd) arrayList.get(position);
populateNativeAdView(nativeAd, ((UnifiedNativeAdViewHolder) holder).getAdView());
break;
case MENU_ITEM_VIEW_TYPE:
default:
final MainAdapterViewHolder mainAdapterViewHolder = (MainAdapterViewHolder) holder;
final VideoListModel folderVideoModel = (VideoListModel) arrayList.get(position);
mainAdapterViewHolder.title.setText("" + folderVideoModel.getPath());
mainAdapterViewHolder.thumbnail.setImageResource(R.drawable.ic_folder);
break;
}
}
public class MainActivity extends AppCompatActivity {
private final ArrayList<NormalFile> list = new ArrayList<>();
private final List<VideoListModel> models = new ArrayList<>();
private final Map<String, VideoListModel> files = new HashMap<>();
private DbHelper db;
MainListAdapter adapter;
private final FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
List<Object> arrayListVideos = new ArrayList<>();
List<UnifiedNativeAd> nativeAds = new ArrayList<>();
public static final int NUMBER_OF_ADS = 1;
AdLoader adLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Constants.getDbHelper(this);
loadVideos();
RecyclerView recyclerView = findViewById(R.id.main_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new MainListAdapter(this, arrayListVideos);
recyclerView.setAdapter(adapter);
}
private void loadVideos() {
FileFilter.getFiles(this, new FilterResultCallback<NormalFile>() {
@Override
public void onResult(List<Directory<NormalFile>> directories) {
for (Directory<NormalFile> directory : directories) {
list.addAll(directory.getFiles());
for (int i = 0; i < directory.getFiles().size(); i++) {
File f = new File(directory.getFiles().get(i).getPath());
String parent = Objects.requireNonNull(f.getParent()).substring(f.getParent().lastIndexOf("/") + 1);
if (parent.equals("0")) {
VideoListModel vlm = new VideoListModel();
vlm.setFolder(false);
vlm.setFile(f);
vlm.setPath(f.getPath());
vlm.setDuration("");
models.add(vlm);
} else {
if (files.containsKey(parent)) {
VideoListModel vlm = files.get(parent);
assert vlm != null;
vlm.getFiles().add(f);
vlm.setPath(f.getParent());
} else {
VideoListModel vlm = new VideoListModel();
vlm.setFolder(true);
vlm.setFolderName(parent);
vlm.setPath(f.getParent());
List<File> fileList = new ArrayList<>();
fileList.add(f);
vlm.setFiles(fileList);
files.put(parent, vlm);
}
}
}
}
models.addAll(files.values());
arrayListVideos.add(models);
for (int i = 0; i < models.size(); i++) {
Log.d("TAG", "onResult: "+ models.get(i).getPath() + " 2 " + models.get(i).isFolder());
}
adapter.notifyDataSetChanged();
//sortByName();
new ThumbnailLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new TimeAndSizeLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
getSupportLoaderManager().destroyLoader(3);
}
}, new String[]{"mp4", "mov", "wmv", "avi", "avchd", "webm", "m4v", "mkv", "3gp", "3g2", "flv", "m3u8"});
}
@SuppressLint("StaticFieldLeak")
private class TimeAndSizeLoader extends AsyncTask<Void, Integer, Void> {
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
adapter.notifyItemChanged(values[0]);
}
@Override
protected Void doInBackground(Void... voids) {
for (int i = 0; i < models.size(); i++) {
if(models.get(i).getFile() != null){
FileStore fs = db.getFileByName(models.get(i).getFile().getName());
VideoListModel vlm = models.get(i);
if (fs != null) {
if(fs.getDuration() != null){ // for file
vlm.setDuration(fs.getDuration());
}else {
fs.setDuration(Constants.getDuration(vlm.getFile().getPath()));
vlm.setDuration(fs.getDuration());
db.insertOrUpdateFile(fs);
}
}else {
vlm.setDuration(Constants.getDuration(vlm.getFile().getPath()));
FileStore fss = new FileStore();
fss.setName(vlm.getFile().getName());
fss.setParent(vlm.getFile().getParent());
fss.setUpdatedAt(new Date());
db.insertOrUpdateFile(fss);
models.set(i, vlm);
}
publishProgress(i);
}
}
Log.e("size", db.getFiles().size() + "");
return null;
}
}
@SuppressLint("StaticFieldLeak")
private class ThumbnailLoader extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
adapter.notifyDataSetChanged();
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
adapter.notifyDataSetChanged();
}
@Override
protected Void doInBackground(Void... voids) {
for (int i = 0; i < models.size(); i++) {
if(models.get(i).getFile() != null){
FileStore fs = db.getFileByName(models.get(i).getFile().getName());
VideoListModel vlm = models.get(i);
if (fs != null) {
if(fs.getBitmap() != null){
vlm.setBitmap(BitmapFactory.decodeByteArray(fs.getBitmap(), 0, fs.getBitmap().length));
vlm.setWidth(fs.getWidth());
vlm.setHeight(fs.getHeight());
}else {
mmr.setDataSource(models.get(i).getFile().getPath());
Bitmap bmp = mmr.getFrameAtTime((Long.parseLong(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)) / 2) * 1000, OPTION_CLOSEST_SYNC);
bmp = Constants.resize(bmp, 512, 512);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
vlm.setBitmap(bmp);
fs.setBitmap(byteArray);
fs.setWidth(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)));
fs.setHeight(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)));
vlm.setWidth(fs.getWidth());
vlm.setHeight(fs.getHeight());
db.insertOrUpdateFile(fs);
}
}else {
try {
mmr.setDataSource(models.get(i).getFile().getPath());
Log.e("time", mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION));
//vlm.setDuration(Constants.getDurationByLong(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)));
//models.set(i, vlm);
//publishProgress(i);
Bitmap bmp = mmr.getFrameAtTime((Long.parseLong(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)) / 2) * 1000, OPTION_CLOSEST_SYNC);
bmp = Constants.resize(bmp, 512, 512);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
vlm.setBitmap(bmp);
FileStore fss = new FileStore();
fss.setName(vlm.getFile().getName());
fss.setParent(vlm.getFile().getParent());
fss.setBitmap(byteArray);
fss.setWidth(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)));
fss.setHeight(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)));
fss.setUpdatedAt(new Date());
vlm.setWidth(fss.getWidth());
vlm.setHeight(fss.getHeight());
db.insertOrUpdateFile(fss);
models.set(i, vlm);
}catch (Exception ignored){ }
}
publishProgress(i);
}
}
Log.e("db", db.getFiles().size() + "");
return null;
}
}
private void loadNativeAds() {
AdLoader.Builder builder = new AdLoader.Builder(this,getResources().getString(R.string.native_ad_id));
adLoader = builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
nativeAds.add(unifiedNativeAd);
if (!adLoader.isLoading()) {
insertAdsInMenuItem();
}
}
}).withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
if (!adLoader.isLoading()) {
insertAdsInMenuItem();
}
}
}).build();
adLoader.loadAds(new AdRequest.Builder().build(),NUMBER_OF_ADS);
}
private void insertAdsInMenuItem() {
if (nativeAds.size() < 0 ){
return;
}
int offset = (models.size() / nativeAds.size() + 1 );
int index = 0;
for (UnifiedNativeAd ad:nativeAds){
arrayListVideos.add(index, ad);
index = index + offset;
}
}
}
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public boolean isFolder() {
return folder;
}
public void setFolder(boolean folder) {
this.folder = folder;
}
public int getFileCount() {
return fileCount;
}
public void setFileCount(int fileCount) {
this.fileCount = fileCount;
}
public String getFolderName() {
return folderName;
}
public void setFolderName(String folderName) {
this.folderName = folderName;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public List<File> getFiles() {
return files;
}
public void setFiles(List<File> files) {
this.files = files;
}
我添加了model
,但仍然会出现错误。那我到底犯了什么错?
public class MainListSuperClass {
}
创建类MyUnifiedNativeAd:
public class MyUnifiedNativeAd extends MainListSuperClass{
private UnifiedNativeAd mUnifiedNativeAd;
public MyUnifiedNativeAd(UnifiedNativeAd unifiedNativeAd) {
mUnifiedNativeAd = unifiedNativeAd;
}
public UnifiedNativeAd getUnifiedNativeAd() {
return mUnifiedNativeAd;
}
public void setUnifiedNativeAd(UnifiedNativeAd unifiedNativeAd) {
mUnifiedNativeAd = unifiedNativeAd;
}
}
从MainListSuperClass扩展VideoListModel:
public class VideoListModel extends MainListSuperClass{
...
}
适配器代码:
public class MainListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int MENU_ITEM_VIEW_TYPE = 0;
private static final int UNIFIED_NATIVE_AD_VIEW_TYPE = 1;
private final Context mContext;
private final ArrayList<MainListSuperClass> arrayList;
public MainListAdapter(Context context, ArrayList<MainListSuperClass> arrayList) {
this.mContext = context;
this.arrayList = arrayList;
}
public static class MainAdapterViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView duration;
Chip size;
RelativeLayout path;
ImageView thumbnail;
public MainAdapterViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
duration = itemView.findViewById(R.id.duration);
size = itemView.findViewById(R.id.file_size);
path = itemView.findViewById(R.id.item_path);
thumbnail = itemView.findViewById(R.id.thumbnail);
}
}
@Override
public int getItemCount() {
return arrayList.size();
}
@Override
public int getItemViewType(int position) {
MainListSuperClass recyclerViewItem = arrayList.get(position);
if (recyclerViewItem instanceof MyUnifiedNativeAd) {
return UNIFIED_NATIVE_AD_VIEW_TYPE;
}
return MENU_ITEM_VIEW_TYPE;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
switch (viewType) {
case UNIFIED_NATIVE_AD_VIEW_TYPE:
View unifiedNativeLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.ad_unified, viewGroup, false);
return new UnifiedNativeAdViewHolder(unifiedNativeLayoutView);
case MENU_ITEM_VIEW_TYPE:
default:
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_video_list, viewGroup, false);
return new MainAdapterViewHolder(view);
}
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
int viewType = getItemViewType(position);
switch (viewType) {
case UNIFIED_NATIVE_AD_VIEW_TYPE:
UnifiedNativeAd nativeAd = ((MyUnifiedNativeAd) arrayList.get(position)).getUnifiedNativeAd();
populateNativeAdView(nativeAd, ((UnifiedNativeAdViewHolder) holder).getAdView());
break;
case MENU_ITEM_VIEW_TYPE:
default:
final MainAdapterViewHolder mainAdapterViewHolder = (MainAdapterViewHolder) holder;
final VideoListModel folderVideoModel = (VideoListModel) arrayList.get(position);
mainAdapterViewHolder.title.setText("" + folderVideoModel.getPath());
mainAdapterViewHolder.thumbnail.setImageResource(R.drawable.ic_folder);
break;
}
}
public class MainActivity extends AppCompatActivity {
private final ArrayList<NormalFile> list = new ArrayList<>();
private final Map<String, VideoListModel> files = new HashMap<>();
private DbHelper db;
MainListAdapter adapter;
private final FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
List<MainListSuperClass> arrayListVideos = new ArrayList<>();
List<MyUnifiedNativeAd> nativeAds = new ArrayList<>();
public static final int NUMBER_OF_ADS = 1;
AdLoader adLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Constants.getDbHelper(this);
loadVideos();
RecyclerView recyclerView = findViewById(R.id.main_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new MainListAdapter(this, arrayListVideos);
recyclerView.setAdapter(adapter);
}
private void loadVideos() {
FileFilter.getFiles(this, new FilterResultCallback<NormalFile>() {
@Override
public void onResult(List<Directory<NormalFile>> directories) {
for (Directory<NormalFile> directory : directories) {
list.addAll(directory.getFiles());
for (int i = 0; i < directory.getFiles().size(); i++) {
File f = new File(directory.getFiles().get(i).getPath());
String parent = Objects.requireNonNull(f.getParent()).substring(f.getParent().lastIndexOf("/") + 1);
if (parent.equals("0")) {
VideoListModel vlm = new VideoListModel();
vlm.setFolder(false);
vlm.setFile(f);
vlm.setPath(f.getPath());
vlm.setDuration("");
arrayListVideos.add(vlm);
} else {
if (files.containsKey(parent)) {
VideoListModel vlm = files.get(parent);
assert vlm != null;
vlm.getFiles().add(f);
vlm.setPath(f.getParent());
} else {
VideoListModel vlm = new VideoListModel();
vlm.setFolder(true);
vlm.setFolderName(parent);
vlm.setPath(f.getParent());
List<File> fileList = new ArrayList<>();
fileList.add(f);
vlm.setFiles(fileList);
files.put(parent, vlm);
}
}
}
}
arrayListVideos.addAll(files.values());
for (int i = 0; i < arrayListVideos.size(); i++) {
Log.d("TAG", "onResult: "+ arrayListVideos.get(i).getPath() + " 2 " + arrayListVideos.get(i).isFolder());
}
adapter.notifyDataSetChanged();
//sortByName();
new ThumbnailLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new TimeAndSizeLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
getSupportLoaderManager().destroyLoader(3);
}
}, new String[]{"mp4", "mov", "wmv", "avi", "avchd", "webm", "m4v", "mkv", "3gp", "3g2", "flv", "m3u8"});
}
@SuppressLint("StaticFieldLeak")
private class TimeAndSizeLoader extends AsyncTask<Void, Integer, Void> {
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
adapter.notifyItemChanged(values[0]);
}
@Override
protected Void doInBackground(Void... voids) {
for (int i = 0; i < arrayListVideos.size(); i++) {
if(arrayListVideos.get(i).getFile() != null){
FileStore fs = db.getFileByName(arrayListVideos.get(i).getFile().getName());
VideoListModel vlm = arrayListVideos.get(i);
if (fs != null) {
if(fs.getDuration() != null){ // for file
vlm.setDuration(fs.getDuration());
}else {
fs.setDuration(Constants.getDuration(vlm.getFile().getPath()));
vlm.setDuration(fs.getDuration());
db.insertOrUpdateFile(fs);
}
}else {
vlm.setDuration(Constants.getDuration(vlm.getFile().getPath()));
FileStore fss = new FileStore();
fss.setName(vlm.getFile().getName());
fss.setParent(vlm.getFile().getParent());
fss.setUpdatedAt(new Date());
db.insertOrUpdateFile(fss);
arrayListVideos.set(i, vlm);
}
publishProgress(i);
}
}
Log.e("size", db.getFiles().size() + "");
return null;
}
}
@SuppressLint("StaticFieldLeak")
private class ThumbnailLoader extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
adapter.notifyDataSetChanged();
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
adapter.notifyDataSetChanged();
}
@Override
protected Void doInBackground(Void... voids) {
for (int i = 0; i < arrayListVideos.size(); i++) {
if(arrayListVideos.get(i).getFile() != null){
FileStore fs = db.getFileByName(arrayListVideos.get(i).getFile().getName());
VideoListModel vlm = arrayListVideos.get(i);
if (fs != null) {
if(fs.getBitmap() != null){
vlm.setBitmap(BitmapFactory.decodeByteArray(fs.getBitmap(), 0, fs.getBitmap().length));
vlm.setWidth(fs.getWidth());
vlm.setHeight(fs.getHeight());
}else {
mmr.setDataSource(arrayListVideos.get(i).getFile().getPath());
Bitmap bmp = mmr.getFrameAtTime((Long.parseLong(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)) / 2) * 1000, OPTION_CLOSEST_SYNC);
bmp = Constants.resize(bmp, 512, 512);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
vlm.setBitmap(bmp);
fs.setBitmap(byteArray);
fs.setWidth(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)));
fs.setHeight(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)));
vlm.setWidth(fs.getWidth());
vlm.setHeight(fs.getHeight());
db.insertOrUpdateFile(fs);
}
}else {
try {
mmr.setDataSource(arrayListVideos.get(i).getFile().getPath());
Log.e("time", mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION));
//vlm.setDuration(Constants.getDurationByLong(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)));
//arrayListVideos.set(i, vlm);
//publishProgress(i);
Bitmap bmp = mmr.getFrameAtTime((Long.parseLong(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)) / 2) * 1000, OPTION_CLOSEST_SYNC);
bmp = Constants.resize(bmp, 512, 512);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
vlm.setBitmap(bmp);
FileStore fss = new FileStore();
fss.setName(vlm.getFile().getName());
fss.setParent(vlm.getFile().getParent());
fss.setBitmap(byteArray);
fss.setWidth(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)));
fss.setHeight(Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)));
fss.setUpdatedAt(new Date());
vlm.setWidth(fss.getWidth());
vlm.setHeight(fss.getHeight());
db.insertOrUpdateFile(fss);
arrayListVideos.set(i, vlm);
}catch (Exception ignored){ }
}
publishProgress(i);
}
}
Log.e("db", db.getFiles().size() + "");
return null;
}
}
private void loadNativeAds() {
AdLoader.Builder builder = new AdLoader.Builder(this,getResources().getString(R.string.native_ad_id));
adLoader = builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
nativeAds.add((new MyUnifiedNativeAd(unifiedNativeAd));
if (!adLoader.isLoading()) {
insertAdsInMenuItem();
}
}
}).withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
if (!adLoader.isLoading()) {
insertAdsInMenuItem();
}
}
}).build();
adLoader.loadAds(new AdRequest.Builder().build(),NUMBER_OF_ADS);
}
private void insertAdsInMenuItem() {
if (nativeAds.size() < 0 ){
return;
}
int offset = (arrayListVideos.size() / nativeAds.size() + 1 );
int index = 0;
for (MyUnifiedNativeAd ad:nativeAds){
arrayListVideos.add(index, ad);
index = index + offset;
}
}
}
}
我有一个回收器视图有10个项目。我滚动到页面底部,现在我正尝试为第一个项目调用。当我调用它时,它不会触发第一个项目的。因此,简而言之,我的问题是,当我调用时,其位置没有显示在屏幕上,它是否触发了?。这是我的适配器代码
当我尝试在回收器视图中选择一个元素时,不会调用OnBindViewWholder。我使用的是一个水平布局,所有元素最初都不显示(7个元素中有4个显示,当用户向右移动时,3个元素交替显示)。通常,当用户单击一个元素时,OnBindViewWholder应该被激发,但对我来说却没有发生。它只在初始化时触发。因为它没有激发,所以我不能单击回收器视图中的任何元素。也许和我的布局有关?我不确定 MyAdap
我试图通过使用新的回收器视图列出数据 这是我的 MainActivity.java 主要活动。xml 我的文本视图。xml Logcat: 第78行:
问题内容: 我在扩展的asynctask中遇到此错误,但我确实确定Object []是Void []。 这是我的自定义AsyncTask: 这是产生问题的子类: 最后,这是错误: 我无法解释此异常,因为我将Void作为参数!那不应该是一个对象。你有解决方案吗? 编辑 :ListPalinasAsyncTask.java:19是指: RepeatableAsyncTask.java:43: 编辑2:
我是新的jasper报告。我已经创建了一个报告与SQL服务器存储过程。当查看报告从Swing框架我得到以下异常。 我已经用与sql Server 2000中存储过程定义相同的数据类型定义了报告的参数。 以下是本文的部分。显示存储过程调用的参数和查询的jrxml文件。 我存储过程的一部分如下