2016-10-17 2 views
1

TextView 필드의 문제가 목록보기에 배치됩니다.목록보기에서 문제를 클릭하고 android에서 spannable 문자열을 클릭하십시오.

  • 텍스트 필드에 첫 번째 스팬 가능 문자열이 클릭 가능한 span()이고 다른 두 개는 정적 인 3 개의 스팬 핑 문자열이 있습니다.
  • 내 문제는 목록보기에서 어떤 영역을 클릭하면 목록 항목을 가져 오는 중이지만 다른 두 개의 정적 텍스트 필드를 클릭하면 목록보기 클릭이 검색되지 않습니다.

코드 :

텍스트 필드를 클릭 :

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의 클릭을 감지하지만 목록 항목은 클릭하지 않습니다.

관련 문제