Tjerk Wolternik のSlide ExpandableListAdapterを実装していますが、それを使用しているリストが呼び出されると ClassCastException が発生します。誰かがなぜこれが起こっているのかを理解するのを手伝ってくれることを願っています.
ここに示すように、カスタム配列アダプターで使用しています。
public class ResultsAdapter extends ArrayAdapter<String> {
private final LayoutInflater layoutInflater;
public ResultsAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
layoutInflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
if(convertView == null){
convertView = layoutInflater.inflate(R.layout.row, null); //must be overall layout
}
TextView venName = (TextView) convertView.findViewById(R.id.rowName);
TextView venAddress = (TextView) convertView.findViewById(R.id.rowAdd);
venName.setText(VenueList.getVenueName(position));
venAddress.setText(VenueList.getVenueAddress(position));
return convertView;
}
}
私が使用している ListView は、ここにある ListFragment の拡張です。
public class ListFragmentClickable extends ListFragment{
private OnItemSelectedListener listener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_results, container, false);
return view;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
updateDetail(position); //see bottom
}
public interface OnItemSelectedListener {
public void onItemSelected(String name);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof OnItemSelectedListener) {
listener = (OnItemSelectedListener) activity;
} else {
throw new ClassCastException(activity.toString()
+ " must implement ListFragmentClickable.OnItemSelectedListener");
}
}
public void updateDetail(int position) {
String name = VenueList.getVenueName(position);
listener.onItemSelected(name);
}
}
logcat は、ライブラリのコードのこの部分を指しています (具体的にはfinal LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)target.getLayoutParams();
):
private void updateExpandable(View target, int position) {
final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)target.getLayoutParams();
if(openItems.get(position)) {
target.setVisibility(View.VISIBLE);
params.bottomMargin = 0;
} else {
target.setVisibility(View.GONE);
params.bottomMargin = 0-viewHeights.get(position);
}
}
そして、ここに私のlogcatがあります:
07-31 23:42:20.931: E/AndroidRuntime(3557): FATAL EXCEPTION: main
07-31 23:42:20.931: E/AndroidRuntime(3557): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
07-31 23:42:20.931: E/AndroidRuntime(3557): at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter.updateExpandable(AbstractSlideExpandableListAdapter.java:222)
07-31 23:42:20.931: E/AndroidRuntime(3557): at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter.enableFor(AbstractSlideExpandableListAdapter.java:159)
07-31 23:42:20.931: E/AndroidRuntime(3557): at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter.enableFor(AbstractSlideExpandableListAdapter.java:142)
07-31 23:42:20.931: E/AndroidRuntime(3557): at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter.getView(AbstractSlideExpandableListAdapter.java:64)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.AbsListView.obtainView(AbsListView.java:1449)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.ListView.onMeasure(ListView.java:1103)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3261)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3261)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3261)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3261)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:683)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3261)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3261)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.View.measure(View.java:8532)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewRoot.performTraversals(ViewRoot.java:915)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.view.ViewRoot.handleMessage(ViewRoot.java:1991)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.os.Looper.loop(Looper.java:150)
07-31 23:42:20.931: E/AndroidRuntime(3557): at android.app.ActivityThread.main(ActivityThread.java:4358)
07-31 23:42:20.931: E/AndroidRuntime(3557): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 23:42:20.931: E/AndroidRuntime(3557): at java.lang.reflect.Method.invoke(Method.java:507)
07-31 23:42:20.931: E/AndroidRuntime(3557): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
07-31 23:42:20.931: E/AndroidRuntime(3557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
07-31 23:42:20.931: E/AndroidRuntime(3557): at dalvik.system.NativeStart.main(Native Method)
誰が私に何が起こっているのか説明できますか? レイアウトでリニアレイアウトを使用しているため、キャストの問題が何であるかわかりません。私のレイアウトは、github リンクにあるものとまったく同じです。助けてくれてありがとう。
編集:ここにもrow.xmlがあります:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/rowName"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textStyle="bold"
android:textSize="16dp"
android:focusable="false"
android:paddingLeft="5dp" />
<TextView
android:id="@+id/rowAdd"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="@id/rowName"
android:focusable="false"
android:paddingTop="2dp"
android:paddingLeft="5dp"/>
<TextView
android:id="@+id/rowFit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingTop="5dp"
android:paddingRight="10dp"
android:focusable="false"
android:textStyle="bold"
android:textSize="18dp" />
<TextView
android:id="@+id/rowDist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp"
android:paddingRight="10dp"
android:focusable="false"/>
<!-- below this is xml for slide expandablelistview -->
<Button
android:id="@+id/expandable_toggle_button"
android:text="More"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/text"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/text"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="@+id/expandable"
android:background="#000000">
<!-- put whatever you want in the expandable view -->
<TextView
android:id="@+id/testtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:text="testtestest"
android:paddingRight="10dp"
android:focusable="false"
android:textStyle="bold"
android:textSize="18dp" />
</LinearLayout>
<!-- slide expandablelistview xml ends here -->