真奇怪; 出于某种原因,我很难让 GridView 的子类正确转换。我Caused by: java.lang.ClassCastException: android.widget.GridView cannot be cast to com.dobydigital.dobixchange.CustomGridView
在尝试投射我的 CustomGridView 时得到。这是我的代码
CustomGridView.java
import android.widget.GridView;
public class CustomGridView extends GridView {
文件浏览器片段.java
//# Other stuff omitted for brevity
private CustomGridView gridView;
public class FileBrowserFragment extends Fragment {
//# Stuff
}
//# .........
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
//# This cast here throws the exception
gridView = (CustomGridView) getView().findViewById(R.id.grid_view);
文件浏览器.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_node"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.dobydigital.dobixchange.CustomGridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
android:layout_weight="80" >
<!-- Preview: listitem=@layout/image_tile -->
</com.dobydigital.dobixchange.CustomGridView>
<Button
android:id="@+id/btn_confirm"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Select this Directory" />
</LinearLayout>
我不知道发生了什么事。我以前从未遇到过子类化布局的问题。