Android 从ExpandableListView编辑textView子级(删除线)

Android 从ExpandableListView编辑textView子级(删除线),android,expandablelistview,Android,Expandablelistview,我有一个ExpandableListView和一个OnChildClickListener但是当点击TextView时,我如何向它添加删除线呢 setOnChildClickListener(新的OnChildClickListener()){ 我的活动布局文件是 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"

我有一个
ExpandableListView
和一个
OnChildClickListener
但是当点击
TextView
时,我如何向它添加删除线呢

setOnChildClickListener(新的OnChildClickListener()){

我的活动布局文件是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

    <TextView
        android:id="@+id/calc_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <ExpandableListView
        android:id="@+id/calc_expandable_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000"
        android:listSelector="@android:color/transparent"
        android:transcriptMode="alwaysScroll" />

</LinearLayout>
您必须这样使用:

CharSequence value = ((TextView)((LinearLayout)v).getChildAt(0)).getText();
if(value!=null){
    SpannableString spannableString = new SpannableString(value);
    spannableString.setSpan(new StrikethroughSpan(), 0, value.length(), 0);
    ((TextView)((LinearLayout)v).getChildAt(0)).setText(spannableString);
}

看起来不错,但它在第一行出现错误。我想无法获取子textview。可能需要处理null值。(请参见编辑)我认为这不能用null
v
调用(放置断点以查看出错情况)。我尝试单步执行,但第一行失败。(返回任何内容)。在我的问题中添加了xml代码,如果有兴趣的话。。您的日志中一定有一些内容,请发布错误。非常感谢您的帮助,@ben75:)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_item_child"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/list_item_text_child"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:padding="10dp"
        android:textSize="20sp" />
</LinearLayout>
W/dalvikvm(28424): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0) E/AndroidRuntime(28424): FATAL EXCEPTION: main
E/AndroidRuntime(28424): java.lang.ClassCastException: android.widget.LinearLayout E/AndroidRuntime(28424):     at com.test.skylderhverandre.Calc$1.onChildClick(Calc.java:185)
E/AndroidRuntime(28424):    at
android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:588)
E/AndroidRuntime(28424):    at
android.widget.ExpandableListView.performItemClick(ExpandableListView.java:527)
E/AndroidRuntime(28424):    at
android.widget.AbsListView$PerformClick.run(AbsListView.java:1831)
E/AndroidRuntime(28424):    at
android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(28424):    at
android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(28424):    at android.os.Looper.loop(Looper.java:150)
E/AndroidRuntime(28424):    at
android.app.ActivityThread.main(ActivityThread.java:4385)
E/AndroidRuntime(28424):    at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28424):    at
java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(28424):    at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
E/AndroidRuntime(28424):    at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
E/AndroidRuntime(28424):    at dalvik.system.NativeStart.main(Native Method)
CharSequence value = ((TextView)((LinearLayout)v).getChildAt(0)).getText();
if(value!=null){
    SpannableString spannableString = new SpannableString(value);
    spannableString.setSpan(new StrikethroughSpan(), 0, value.length(), 0);
    ((TextView)((LinearLayout)v).getChildAt(0)).setText(spannableString);
}