我正在制作回收视图,该视图水平获取前一活动中检查的视频缩略图。 我已经在各地使用Log来查找方法是否正常工作。该方法工作正常,我得到的主要问题是在所有的努力之后,视频缩略图没有填充在所提供的空间中,或者我必须说该区域是空白的。什么都没有。
这是我的自定义布局,它会使回收者视图膨胀:
1。 custom_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#212326"
android:orientation="vertical"
android:layout_marginBottom="3dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:scaleType="centerCrop"/></LinearLayout>
现在是editvideo活动,它从前一个片段中获取已检查的文件。
2。 EditVideoActivity.java
public class EditVideoActivity extends AppCompatActivity {
private ImageButton filterButton,cutButton,audioButton;
ArrayList<File> mList = new ArrayList<>();
ListView mListView;
RecyclerView recyclerView;
ViewAdapter viewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_edit_video);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.edit_header_layout);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.back);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
filterButton = (ImageButton) findViewById(R.id.filterVideo);
cutButton = (ImageButton) findViewById(R.id.cutVideo);
audioButton = (ImageButton) findViewById(R.id.musicalNotes);
recyclerView = (RecyclerView) findViewById(R.id.videoGallery);
//checking out for received data
Bundle extras = getIntent().getExtras();
String receivedData = extras.getString("sendData");
Log.e("RECEIVED DATA=====", receivedData);
String filename;
for(int i=0;i<receivedData.substring(1,receivedData.length()-1).split(",").length;i++){
filename = receivedData.split(",")[i];
File file = new File(filename);
Log.e("FILENAME===",filename);
mList.add(file);
}
viewAdapter = new ViewAdapter(mList);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(EditVideoActivity.this,LinearLayoutManager.HORIZONTAL,false);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(viewAdapter);
audioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(EditVideoActivity.this, AudioActivity.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.edit_video, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.moveNext:
Intent intent = new Intent(EditVideoActivity.this,PreviewActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
moveTaskToBack(false);
}
ViewAdapter类在这里:
第3。 ViewAdapter类
class ViewAdapter extends RecyclerView.Adapter<ViewAdapter.ViewHolder> {
private View rootView;
ArrayList<File> files;
private Bitmap bitmap;
public ViewAdapter(ArrayList<File>items) {
files = items;
Log.e("ADAPTER","CONSTRUCTOR CALLED");
//inflating the layout
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.e("ADAPTER","VIEW HOLDER CREATED");
rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_listview,parent,false);
return new ViewHolder(rootView);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.e("ADAPTER",files.get(position).toString());
if (files != null) {
bitmap = ThumbnailUtils.createVideoThumbnail(files.get(position).toString(),1);
}
holder.mImageView.setImageBitmap(bitmap);
// holder.mImageView.setId(position);
}
@Override
public int getItemCount() {
return files.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public ImageView mImageView;
public TextView mTextView;
public ViewHolder(View view){
super(view);
mImageView = (ImageView) view.findViewById(R.id.imageView);
}
}
} }
问题是onBindViewHolder部分 if ,因为由于我正在使用的位图对象而没有加载文件。任何帮助都将受到高度赞赏
**编辑:**
在onBindViewHolder中我测试了使用log in if方法。我得到的是NullPointerException。这意味着它没有制作任何缩略图。
在这里:
if(files != null){
bitmap = ThumbnailUtils.createThumbnail(files.get(position).toString(),1);
Log.e("FILES======",bitmap.toString());
}
在位图定义下方使用Log.e时,Logcat出错
08-08 16:34:12.548 22000-22000/in.pinelane.myhovi E/AndroidRuntime: FATAL EXCEPTION: main
Process: in.pinelane.myhovi, PID: 22000
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at in.pinelane.myhovi.EditVideoActivity$ViewAdapter.onBindViewHolder(EditVideoActivity.java:149)
at in.pinelane.myhovi.EditVideoActivity$ViewAdapter.onBindViewHolder(EditVideoActivity.java:118)