此处控制台显示ClassCastException,但不显示错误行号吗?有人在这帮我吗?
如果有人想找到确切的错误代码,那么建议我?
这里是我使用ListView的xml。
我尝试过
1)删除了以编程方式设置的参数
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adlayout"
android:background="@color/md_white_0">
<com.os.folder.and.file.locker.files.widget.BGridView
android:id="@+id/hide_view_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:numColumns="3"
android:stretchMode="columnWidth" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/hide_btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="@color/file_add"
android:onClick="onClick"
android:src="@drawable/ic_action_new" />
<LinearLayout
android:id="@+id/file_bottom_layout_tips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/unrecord" />
<TextView
android:id="@+id/file_bottom_txt_tips"
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center"
android:text=""
android:textColor="@color/md_black_2"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/pic_hide_btn_edit"
android:layout_width="match_parent"
android:layout_height="@dimen/title_height"
android:layout_above="@+id/adlayout"
android:layout_alignParentRight="true"
android:background="@color/md_black_1"
android:visibility="visible"
android:weightSum="4">
<LinearLayout
android:id="@+id/pic_hide_img_cancel"
android:layout_width="0dp"
android:layout_height="@dimen/title_height"
android:layout_weight="1"
android:gravity="center"
android:onClick="onClick">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/close" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="@dimen/title_height"
android:layout_weight="1"
android:gravity="center">
<CheckBox
android:id="@+id/item_file_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector" />
</LinearLayout>
<LinearLayout
android:id="@+id/pic_hide_img_recovery"
android:layout_width="0dp"
android:layout_height="@dimen/title_height"
android:layout_weight="1"
android:gravity="center"
android:onClick="onClick">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/unlock" />
</LinearLayout>
<LinearLayout
android:id="@+id/pic_hide_img_del"
android:layout_width="0dp"
android:layout_height="@dimen/title_height"
android:layout_weight="1"
android:gravity="center"
android:onClick="onClick">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/delete" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/adlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" />
</RelativeLayout>
这里是Java文件,我已经从此处实现了listView
package com.os.folder.and.file.locker.files.activity;
import android.content.Intent;
import com.os.folder.and.file.locker.R;
import com.os.folder.and.file.locker.data.GroupImage;
import com.os.folder.and.file.locker.data.HideImage;
import com.os.folder.and.file.locker.files.adapter.BaseHideAdapter.OnListener;
import com.os.folder.and.file.locker.files.adapter.PicHideAdapter;
import com.os.folder.and.file.locker.files.entity.HideImageExt;
import com.os.folder.and.file.locker.files.widget.BGridView;
import com.os.folder.and.file.locker.service.GroupImageService;
import com.os.folder.and.file.locker.service.ImageService;
import java.util.List;
public class PicHideActivity extends BaseHideActivity implements OnListener {
protected static final String TAG = "PicHideActivity";
private int itemSize;
protected GroupImageService mGroupImageService;
protected ImageService mImageService;
protected void initUI() {
setContentView((int) R.layout.activity_file_hide_group);
setUI();
setTitleRID(R.string.pic_preview_title, R.string.pic_preview_title_edit);
setGridView();
this.mFile_bottom_txt_tips.setText(R.string.file_hide_txt_add_pic);
this.rid_string_type = R.string.pic_preview;
}
private void setGridView() {
this.itemSize = ((BGridView) findViewById(R.id.hide_view_list)).setGridView(getWindowManager(), 4, 4);
}
void initAdapter() {
BGridView adapterView = findViewById(R.id.hide_view_list);
this.mGroupImageService = new GroupImageService(this);
this.mImageService = new ImageService(this);
this.mBaseHideAdapter = new PicHideAdapter(this, this, this.itemSize);
adapterView.setAdapter(this.mBaseHideAdapter);
}
boolean delFolder() {
return false;
}
void addFolder() {}
public void addFile() {
Intent intent = new Intent(this, PicPreViewActivity.class);
intent.putExtra("beyondGroupId", this.mBaseHideAdapter.getGruopID());
startActivity(intent);
}
protected void recoveryFiles() {
for (Object imageModelView: this.mBaseHideAdapter.getHitFiles()) {
this.mImageService.unHideImage((HideImageExt) imageModelView);
}
}
protected void delFiles() {
for (Object hideImageExt: this.mBaseHideAdapter.getHitFiles()) {
this.mImageService.deleteAudioByPath((HideImageExt)
hideImageExt);
}
}
protected void openHolder(int groupID) {
List < GroupImage > groupList = this.mGroupImageService.getGroupFiles(groupID);
List < HideImage > list = this.mImageService.getHideImages(groupID);
this.mBaseHideAdapter.setHitFiles(groupList, list, groupID);
setHasData(groupList, list);
}
public void openHolder(Object object) {
GroupImage data = (GroupImage) object;
int groupID = -1;
if (data != null) {
groupID = data.getId().intValue();
}
openHolder(groupID);
}
}
这是适配器代码
package com.os.folder.and.file.locker.files.adapter;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
//import android.widget.AbsListView.LayoutParams;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions.Builder;
import com.nostra13.universalimageloader.core.ImageLoader;
import
com.nostra13.universalimageloader.core.download.ImageDownloader.Scheme;
import com.os.folder.and.file.locker.R;
import com.os.folder.and.file.locker.data.GroupImage;
import com.os.folder.and.file.locker.data.HideImage;
import com.os.folder.and.file.locker.files.activity.PhotoPreViewActivity;
import com.os.folder.and.file.locker.files.entity.GroupImageExt;
import com.os.folder.and.file.locker.files.entity.HideImageExt;
import java.util.ArrayList;
import java.util.List;
public class PicHideAdapter extends BaseHideAdapter {
private static final String TAG = "PicHideAdapter";
protected ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new Builder().showStubImage(R.drawable.default_picture).showImageForEmptyUri((int) R.drawable.default_picture).showImageOnFail((int) R.drawable.default_picture).cacheInMemory(true).cacheOnDisc(true).build();
private ViewGroup.LayoutParams params;
class PicHolder {
Object mData;
ImageView mImg_pre_preview;
View mItem_file_ok;
View mItem_file_pic;
PicHolder() {}
}
public PicHideAdapter(Context context, OnListener onListern, int itemSize) {
super(context, onListern);
this.params = new ViewGroup.LayoutParams(itemSize, itemSize);
}
public void clear() {
super.clear();
if (this.imageLoader != null) {
this.imageLoader.stop();
this.imageLoader = null;
}
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = this.mInflater.inflate(R.layout.item_file_hide_pic, null);
PicHolder picHolder = new PicHolder();
picHolder.mItem_file_pic = convertView.findViewById(R.id.item_file_pic);
picHolder.mItem_file_ok = convertView.findViewById(R.id.item_file_ok);
picHolder.mImg_pre_preview = (ImageView)
convertView.findViewById(R.id.img_pre_preview);
convertView.setTag(picHolder);
// convertView.setLayoutParams(this.params);
}
initView(convertView, position);
return convertView;
}
protected void initView(View view, final int position) {
int i = 8;
final PicHolder fileHolder = (PicHolder) view.getTag();
fileHolder.mImg_pre_preview.setImageBitmap(null);
Object data = getItem(position);
fileHolder.mData = data;
if (data instanceof HideImageExt) {
final HideImageExt hideImageView = (HideImageExt) data;
this.imageLoader.displayImage(Scheme.THUMBNAIL.wrap(hideImageView.getNewPathUrl()), fileHolder.mImg_pre_preview, this.options);
if (this.edit) {
View view2 = fileHolder.mItem_file_ok;
if (hideImageView.isEnable()) {
i = 0;
}
view2.setVisibility(i);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
boolean z;
int i = 0;
HideImageExt hideImageExt = hideImageView;
if (hideImageView.isEnable()) {
z = false;
} else {
z = true;
}
hideImageExt.setEnable(z);
View view = fileHolder.mItem_file_ok;
if (!hideImageView.isEnable()) {
i = 8;
}
view.setVisibility(i);
PicHideAdapter.this.updateSelect();
}
});
view.setOnLongClickListener(null);
return;
}
fileHolder.mItem_file_ok.setVisibility(8);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(PicHideAdapter.this.context, PhotoPreViewActivity.class);
intent.putParcelableArrayListExtra("list", (ArrayList)
PicHideAdapter.this.mList_HideFile);
intent.putExtra("id", position);
PicHideAdapter.this.context.startActivity(intent);
}
});
view.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
PicHideAdapter.this.doVibrator(PicHideAdapter.this.context);
PicHideAdapter.this.mOnListern.onLongClick(hideImageView);
return false;
}
});
} else if (data instanceof GroupImageExt) {
final GroupImageExt groupImageView = (GroupImageExt) data;
fileHolder.mItem_file_ok.setVisibility(8);
fileHolder.mImg_pre_preview.setImageResource(R.drawable.folder);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (PicHideAdapter.this.edit) {
PicHolder fileHolder = (PicHolder) v.getTag();
groupImageView.setEnable(!groupImageView.isEnable());
} else if (PicHideAdapter.this.mOnListern != null) {
PicHideAdapter.this.mOnListern.openHolder(groupImageView);
}
}
});
}
}
public void setHitFiles(List < ?>listGroup, List < ?>listFile, int groupID) {
this.mList_Group = GroupImageExt.transList((List < GroupImage > ) listGroup);
this.mList_HideFile = HideImageExt.transList((List < HideImage > ) listFile);
setGroup(groupID);
notifyDataSetChanged();
}
}
答案 0 :(得分:0)
LayoutParams lp = new LayoutParams(-2, -2);
lp.setMargins(margin, margin, margin, margin);
setLayoutParams(lp);
已解决..通过删除此参数