2016-10-17 10 views
1

TextViewフィールドの問題がリストビューに配置されています。リストビューで問題をクリックし、アンドロイドでスパニング可能な文字列を入力してください

  • テキストフィールドには、最初のスパン可能な文字列がクリック可能なspan()と他の2つは静的な3つのスパン可能な文字列があります。
  • リストビュー内の任意の領域をクリックするとリストアイテムがクリックされていますが、他の2つの静的テキストフィールドをクリックするとリストビューのクリックが検出されません。

コード:

のTextFieldをクリック:

holder.txtmail = new SpannableString(rowItems.get(position).getTxtEmail()); 
holder.txtmail.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.color)), 0, holder.txtmail.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
holder.txtmail.setSpan(new MyClickableSpan(strText), 0, holder.txtmail.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
holder.mainName.setText(holder.txtmail); 
holder.txtSt = new SpannableString(rowItems.get(position).getTxtSt()); 
holder.txtSt.setSpan(new ForegroundColorSpan(Color.BLACK),0, holder.txtSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
holder.mainName.append(holder.txtSt); 
holder.txtEvt = new SpannableString(rowItems.get(position).getTxtEvt()); 
holder.txtEvt.setSpan(new ForegroundColorSpan(Color.BLACK), 0, holder.txtEvt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
holder.txtEvt.setSpan(new StyleSpan(Typeface.BOLD), 0, holder.txtEvt.length(), 0); 
holder.txtEvt.setSpan(new MyClickableSpan(rowItems.get(position).getTxtEvt()), 0, holder.txtmail.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
holder.mainName.append(holder.txtEvt); 
holder.mainName.setMovementMethod(LinkMovementMethod.getInstance()); 
holder.mainName.setFocusable(false); 
holder.mainName.setClickable(false); 

private class MyClickableSpan extends ClickableSpan { 
    String clicked; 

    private MyClickableSpan(String string) { 
     super(); 
     this.clicked = string; 
    } 

    public void onClick(View tv) { 
     Toast.makeText(context, "" + clicked, Toast.LENGTH_SHORT).show(); 
    } 

    public void updateDrawState(TextPaint ds) { 
     ds.setUnderlineText(false); 
    } 
} 

リストビューをクリックして:リストビューラ用

getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { 
     Toast.makeText(getActivity(), "Item: " + position, Toast.LENGTH_SHORT).show(); 
    } 
}); 

XML YOUT

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:layout_marginStart="40dp" 
     android:layout_marginTop="5dp" 
     android:contentDescription="@string/app_name" /> 

    <TextView 
     android:id="@+id/ltMain" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="15dp" 
     android:layout_toEndOf="@+id/icon" 
     android:textSize="12sp" /> 

    <TextView 
     android:id="@+id/ltSub" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/ltMain" 
     android:layout_marginBottom="10dp" 
     android:layout_marginStart="15dp" 
     android:layout_toEndOf="@+id/icon" 
     android:textSize="12sp" /> 
</RelativeLayout> 
+1

アイテムレイアウトを追加する必要があります。 – MinWan

答えて

1

クリック不可のアイテムにもMyClickableSpanを追加し、リストアイテムをクリックしてください。

0

あなたはfalseに他の二つのTextViewsのクリック可能なプロパティを設定する必要があります。 デフォルトでクリック可能なので、クリックするとTextViewのクリックが検出され、リスト項目のクリックは検出されません。

関連する問題