SpannableStringBuilder | Photo-text - 图文混排
kandi X-RAY | SpannableStringBuilder Summary
kandi X-RAY | SpannableStringBuilder Summary
Photo-text
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Initializes the view
- Set spannable text
- Get the list view at a specific position
- Returns the number of elements in the list
- Gets the item at a given position
SpannableStringBuilder Key Features
SpannableStringBuilder Examples and Code Snippets
Community Discussions
Trending Discussions on SpannableStringBuilder
QUESTION
class EllipsizedTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0): AppCompatTextView(context, attrs, defStyleAttr) {
private var ellipsis = getDefaultEllipsis().toString()
private var ellipsisColor = getDefaultEllipsisColor()
private var isEllipsis = false
private var ellipsizedText: CharSequence? = null
private var callbackEllipsized: MoreClickableSpan? = null
init {
attrs?.let { attributeSet ->
context.theme.obtainStyledAttributes(attributeSet, R.styleable.EllipsizedTextView, 0, 0).apply {
ellipsis = getString(R.styleable.EllipsizedTextView_ellipsis) ?: getDefaultEllipsis().toString()
ellipsisColor = getColor(R.styleable.EllipsizedTextView_ellipsisColor, getDefaultEllipsisColor())
recycle()
}
}
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
/*
Prepare to set custom ellipsize text
*/
val availableScreenWidth = measuredWidth - compoundPaddingLeft.toFloat() - compoundPaddingRight.toFloat()
var availableTextWidth = availableScreenWidth * maxLines
ellipsizedText = TextUtils.ellipsize(text, paint, availableTextWidth, ellipsize, false) { start, end ->
isEllipsis = start != 0 && end >= 65
}
if (isEllipsis) { // check if current text is ellipsized or not
printLog("isEllipsis: $ellipsizedText ellipsis: $ellipsis, text : $text")
// If the ellipsizedText is different than the original text, this means that it didn't fit and got indeed ellipsized.
// Calculate the new availableTextWidth by taking into consideration the size of the custom ellipsis, too.
availableTextWidth = (availableScreenWidth - paint.measureText(ellipsis)) * maxLines
ellipsizedText = TextUtils.ellipsize(text, paint, availableTextWidth, ellipsize, false){ start, end ->
isEllipsis = start != 0 && end >= 65
}
}
setEllipsizedText(ellipsizedText, isEllipsis)
}
private fun setEllipsizedText(value: CharSequence?, isEllipsized: Boolean){
printLog("setEllipsizedText > $isEllipsized")
if(isEllipsized){
val resultText = "$value$ellipsis"
val startPoint = resultText.indexOf(ellipsis)
val endPoint = startPoint + ellipsis.length
val spannable = SpannableString(resultText).apply {
callbackEllipsized?.let { callback ->
printLog("setEllipsizedText > implement callbackEllipsized")
// set event click on spannable
setSpan(callback, startPoint, endPoint, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
// set color on target text while enable to click
setSpan(ForegroundColorSpan(ellipsisColor), startPoint, endPoint, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
//val defaultEllipsisStart = value.indexOf(getDefaultEllipsis())
//val defaultEllipsisEnd = defaultEllipsisStart + 1
//text = spannableStringBuilder.append(ellipsizedText).replace(defaultEllipsisStart, defaultEllipsisEnd, ellipsisSpannable)
text = spannable
movementMethod = LinkMovementMethod.getInstance()
printLog("setEllipsizedText > text : $text")
}
}
private fun getDefaultEllipsis(): Char {
return Typography.ellipsis
}
private fun getDefaultEllipsisColor(): Int {
return textColors.defaultColor
}
fun setActionClickEllipse(callback: MoreClickableSpan){
this.callbackEllipsized = callback
}
fun isReadMore(): Boolean = isEllipsis
@Suppress("unused_parameter")
fun printLog(msg: String) { }
open class MoreClickableSpan : ClickableSpan() {
override fun onClick(widget: View) {}
override fun updateDrawState(ds: TextPaint) {}
}
}
...ANSWER
Answered 2022-Jan-28 at 05:25Why don't you add this to your TextView
in the xml
file?It will limit it to 65 chars and it will show ellipse after that
QUESTION
I want to add EditText to the listview, but I can't do it smoothly. Please guide. If it is List, it is normal, but DakaHinbanClass is used, How to write code that uses Class
The data is obtained from MySQL, and the content can be displayed normally at present. I want to change the production quantity directly in the listview, but when running, the position of line 195 always reports an error.
ErrorCode:
2022-03-31 15:58:14.780 13403-13403/com.ree.kms E/AndroidRuntime: FATAL EXCEPTION: main Process: com.ree.kms, PID: 13403 java.lang.ClassCastException: android.text.SpannableStringBuilder cannot be cast to com.ree.kms.DakaHinbanClass at
com.ree.kms.DakaListAdapterClass$MyTextWatcher.afterTextChanged(DakaListAdapterClass.java:195)
at android.widget.TextView.sendAfterTextChanged(TextView.java:8336) at android.widget.TextView.setText(TextView.java:4399) at android.widget.TextView.setText(TextView.java:4247) at android.widget.EditText.setText(EditText.java:90) at android.widget.TextView.setText(TextView.java:4222) at com.ree.kms.DakaListAdapterClass.getView(DakaListAdapterClass.java:101) at android.widget.AbsListView.obtainView(AbsListView.java:2474) at android.widget.ListView.makeAndAddView(ListView.java:1920) at android.widget.ListView.fillDown(ListView.java:717) at android.widget.ListView.fillFromTop(ListView.java:778) at android.widget.ListView.layoutChildren(ListView.java:1701) at android.widget.AbsListView.onLayout(AbsListView.java:2235) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1189) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844) at android.widget.LinearLayout.onLayout(LinearLayout.java:1753) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844) at android.widget.LinearLayout.onLayout(LinearLayout.java:1753) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2740) at android.view.View.layout(View.java:16953) at android.view.ViewGroup.layout(ViewGroup.java:5579) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2562) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2265) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1323) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6718) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894) at android.view.Choreographer.doCallbacks(Choreographer.java:696) at android.view.Choreographer.doFrame(Choreographer.java:631) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5765) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
DakaListAdapterClass
...ANSWER
Answered 2022-Apr-01 at 05:56After the user changes the string inside the EditText
, the method afterTextChanged(Editable s)
is called, and s
represents the new edited String. You want to update the DakaHinbanClass object inside the list, so you can't just conver a String an object (this String is only one class member of this object class, right?)
If you want to update the Query value inside this object, first get the object and then set the class member value to the new String, like this:
QUESTION
I am attempting to unit test a method that is part of my use case layer of an Android app. The method receives an XML RSS feed and returns it to the view model as GSON-parsed objects. The testing class is annotated with @RunWith(RobolectricTestRunner::class)
.
The test fails because a java.lang.ExceptionInInitializerError
(among others) is thrown by .fromHtml()
within this method of the use case class:
ANSWER
Answered 2022-Mar-21 at 13:56I have discovered a solution. Add the following to the android
section of the module build.gradle
:
QUESTION
An exception was thrown: NoSuchMethodError: The method 'toDate' was called on null
.
Exception:
...ANSWER
Answered 2022-Mar-18 at 20:22You need to check if time
is null or not. check the code below.
QUESTION
I'm trying to Implement Multiple Click on a Single TextView using spannable builder , I tried multiple ways to implement click on spannable string but failed , please guide me what I have done/or doing worng here.
...ANSWER
Answered 2021-Oct-29 at 11:14so the issue was with this line
QUESTION
Problem: MyAutoCompleteTextView.**showDropDown()**
will work when called by the onFocusChange
but won't work when called by the onTextChanged
. During my debug, the onTextChanged
method gets called correctly when I want it to execute the showDropDown()
according to the logging message I created, just nothing happens. I noticed there is a SpannableStringBuilder
error that occurs prior, but as I recall (could be wrong) when I checked on this error in the past, this is a common error with an open ticket. I wasn't really sure it is the cause.
What I'm trying to do: ... is what everyone that asks this type of question wants to do, get the AutoCompleteTextView
to show the full list anytime the AutoCompleteTextView
is focused and empty (my first item is: "")
What I have tried: I've tried many "green checked" solutions on this forum, but none of them have worked at present EXCEPT when first focused. They will cause the full items list to present, but it is on the backspacing back to zero that it will not. I'm using a combination of change listeners
as most suggestions have. I just really thought this would work based on the logging values and it being called at the proper time?
My logging statement: which writes when I want it to showing the method gets called when I like.
...ANSWER
Answered 2022-Jan-12 at 02:56QUESTION
I am on a Notetaking project where I want to allow users to insert images in their notes. the image will be on top or below of texts. this is the code by which I am trying to get the image into the editText field. But after selecting the image it does not show in the edit Text. it will be very helpful if anybody can help me. this is in my onCreate:
...ANSWER
Answered 2021-Dec-20 at 05:18Image will show in image view
, if you want to upload image from gallery then this code will work
QUESTION
I was working on a project, where There is a table named Messages(uuid, body, metadata_list, ... ...)
, and I want to perform bulk update on message_body, and metadata_list columns. I followed this answer.
I created a data class
...ANSWER
Answered 2021-Nov-07 at 04:56@Update
abstract fun update(myTuple : MyTuple)
//This function is under a transaction so it will be commited to the database
//all at the same time.
@Transaction
fun update(list : List){
list.forEach{
update(it)
}
}
QUESTION
I'm trying to build a String that has two different custom fonts applied to it. I've appended the two strings with the respective font into a string builder, but this does nothing to the String at all? Does anyone know why?
...ANSWER
Answered 2021-Oct-14 at 22:03You can use this custom TypefaceSpan
class:
QUESTION
Problem: In the debug report below, I think I understand the issue is the setSpan
starts at a negative vs 0. But I don't know what that means or whether I can fix it because it isn't traced to any particular layout, class or function I have created? I don't have any code in this activity dealing with setSpan
?
What appears to be happening: It seems to be occurring with AutoCompleteTextViews
on my AddNote
activity. The irony, this activity is really a duplicate of the EditNote
activity in layout and function, and doesn't occur with EditNote
. However, one difference is with the AddNote
activity these have setOnFocusChangedListener
s.
It also, in one way, appears random. Sometimes I simply click on the AutoCompleteTextView
and it will trigger this error. Other times, after data is selected or entered, when focus changes it occurs.
What is expected: AutoCompleteTextViews
are dropdown lists with the option to select or to add something new. I've been working with this activity for months with no issue, then this just started to happen.
Below, the debug doesn't identify any of my classes or resources triggering this issue, I just appears to be occurring based upon the few details above. That's one reason I'm not certain if it is something I can change for fix and wanted to reach out.
AutoCompleteTextView object setups
...ANSWER
Answered 2021-Sep-17 at 12:02This appears to be a common and frequent issue posted on Issue Tracker. I added comments to the following issue which appeared to be similar and had been assigned. https://issuetracker.google.com/issues/119349156
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SpannableStringBuilder
You can use SpannableStringBuilder like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the SpannableStringBuilder component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page