- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 Activity ListView
。在每个列表项中显示 TextView
。使用这些方法切换所选位置的属性 EditText#setTextIsSelectable
、 EditText#setEllipsize
和 EditText#setSingleLine
。点击第一项效果很好。但是当我点击另一个项目时,我得到了 StackOverFlowError
。
下面是我的代码示例。如果我做错了,请告诉我。
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class SelectableTextListActivity extends Activity {
private static final String TAG = "HistoryActivity";
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);//only ListView present in this layout
listView = (ListView) findViewById(R.id.myList);
String items[] = {"Some Information Some Information Some Information", "Some Information Some Information Some Information", "Some Information Some Information Some Information", "Some Information Some Information Some Information",
"Some Information Some Information Some Information", "Some Information Some Information Some Information", "Some Information Some Information Some Information", "Some Information Some Information Some Information"};
final MyAdapter myAdapter = new MyAdapter(this, items);
listView.setAdapter(myAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick: position=" + position);
myAdapter.setSelectedPosition(position);
myAdapter.notifyDataSetChanged();
}
});
}
private static class MyAdapter extends BaseAdapter {
private static final String TAG = "HistoryAdapter";
private final LayoutInflater inflater;
private int mSelectedPosition = -1;
private String[] mItems;
public MyAdapter(Context context, String[] items) {
mItems = items;
inflater = LayoutInflater.from(context);
}
public void setSelectedPosition(int mSelectedPosition) {
this.mSelectedPosition = mSelectedPosition;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.selectable_text_layout, null, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String item = getItem(position);
viewHolder.selectableTV.setText(item);
if (position == mSelectedPosition) {
Log.d(TAG, "getView() called with: " + "position = [" + position + "], selected = " + true);
viewHolder.selectableTV.setTextIsSelectable(true);
viewHolder.selectableTV.setSingleLine(false);
viewHolder.selectableTV.setEllipsize(null);
} else {
Log.d(TAG, "getView() called with: " + "position = [" + position + "], selected = " + false);
viewHolder.selectableTV.setTextIsSelectable(false);
viewHolder.selectableTV.setSingleLine(true);
viewHolder.selectableTV.setEllipsize(TextUtils.TruncateAt.END);
}
return convertView;
}
@Override
public String getItem(int position) {
return mItems[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getCount() {
return mItems.length;
}
private class ViewHolder {
public final TextView selectableTV;
ViewHolder(View convertView) {
selectableTV = (TextView) convertView.findViewById(R.id.selectableTextView);
}
}
}
}
布局文件:selectable_text_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/selectableTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:ellipsize="end"
android:focusable="false"
android:text="My app name"
android:textAppearance="?android:textAppearanceMedium" />
</LinearLayout>
堆栈跟踪是
D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
at java.lang.Class.isInstance(Class.java:1484)
at android.text.SpannableStringInternal.getSpans(SpannableStringInternal.java:217)
at android.text.SpannedString.getSpans(SpannedString.java:25)
at android.text.SpannableStringInternal.<init>(SpannableStringInternal.java:40)
at android.text.SpannableString.<init>(SpannableString.java:30)
at android.widget.TextView.removeSuggestionSpans(TextView.java:4200)
at android.widget.TextView.setText(TextView.java:3926)
at android.widget.TextView.setText(TextView.java:3911)
at android.widget.TextView.getIterableTextForAccessibility(TextView.java:9047)
at android.view.View.onInitializeAccessibilityEventInternal(View.java:5450)
at android.view.View.onInitializeAccessibilityEvent(View.java:5422)
at android.widget.TextView.onInitializeAccessibilityEvent(TextView.java:8402)
at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5293)
at android.view.View.sendAccessibilityEventUnchecked(View.java:5280)
at android.view.View.sendAccessibilityEventInternal(View.java:5257)
at android.view.View.sendAccessibilityEvent(View.java:5226)
at android.widget.TextView.sendAccessibilityEvent(TextView.java:8571)
at android.widget.TextView.onSelectionChanged(TextView.java:7584)
at android.widget.TextView.spanChange(TextView.java:7784)
at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:9478)
at android.text.SpannableStringInternal.sendSpanAdded(SpannableStringInternal.java:314)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:138)
at android.text.SpannableString.setSpan(SpannableString.java:46)
at android.text.SpannableStringInternal.<init>(SpannableStringInternal.java:52)
at android.text.SpannableString.<init>(SpannableString.java:30)
at android.widget.TextView.removeSuggestionSpans(TextView.java:4200)
at android.widget.TextView.setText(TextView.java:3926)
at android.widget.TextView.setText(TextView.java:3911)
at android.widget.TextView.getIterableTextForAccessibility(TextView.java:9047)
at android.view.View.onInitializeAccessibilityEventInternal(View.java:5450)
at android.view.View.onInitializeAccessibilityEvent(View.java:5422)
at android.widget.TextView.onInitializeAccessibilityEvent(TextView.java:8402)
at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5293)
at android.view.View.sendAccessibilityEventUnchecked(View.java:5280)
at android.view.View.sendAccessibilityEventInternal(View.java:5257)
at android.view.View.sendAccessibilityEvent(View.java:5226)
at android.widget.TextView.sendAccessibilityEvent(TextView.java:8571)
at android.widget.TextView.onSelectionChanged(TextView.java:7584)
at android.widget.TextView.spanChange(TextView.java:7784)
at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:9478)
at android.text.SpannableStringInternal.sendSpanAdded(SpannableStringInternal.java:314)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:138)
at android.text.SpannableString.setSpan(SpannableString.java:46)
at android.text.SpannableStringInternal.<init>(SpannableStringInternal.java:52)
at android.text.SpannableString.<init>(SpannableString.java:30)
at android.widget.TextView.removeSuggestionSpans(TextView.java:4200)
at android.widget.TextView.setText(TextView.java:3926)
at android.widget.TextView.setText(TextView.java:3911)
at android.widget.TextView.getIterableTextForAccessibility(TextView.java:9047)
at android.view.View.onInitializeAccessibilityEventInternal(View.java:5450)
at android.view.View.onInitializeAccessibilityEvent(View.java:5422)
at android.widget.TextView.onInitializeAccessibilityEvent(TextView.java:8402)
at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5293)
at android.view.View.sendAccessibilityEventUnchecked(View.java:5280)
at android.view.View.sendAccessibilityEventInternal(View.java:5257)
at android.view.View.sendAccessibilityEvent(View.java:5226)
at android.widget.TextView.sendAccessibilityEvent(TextView.java:8
09-13 00:48:45.483 8705-8705/club.apptu.edittextlocalhistory D/Error: ERR: TOTAL BYTES WRITTEN: 16156172
09-13 00:48:45.483 8705-8705/club.apptu.edittextlocalhistory E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
09-13 00:48:45.484 8705-8705/club.apptu.edittextlocalhistory E/AndroidRuntime: Error reporting crash android.os.TransactionTooLargeException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:496)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4144)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
提前致谢。
编辑:
在 ListView#onItemClickListener
中调用 notifyDatasetChanged
时出现问题。
最佳答案
我递归地调用了 onBackPressed()
,这导致了我的 StackOverFlowError
。
关于android - java.lang.StackOverflowError : stack size 8MB while Enabling/Disabling TextView#setTextIsSelectable in ListView Adapter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37066986/
我使用 jQuery 禁用选择下拉列表中的选项。我需要知道使用之间的区别 prop('disabled','disabled') 和 prop('disabled',true) 两者几乎都适用于所有浏
.attr('disabled', 'disabled') 和 .attr('disabled', true) 在我的代码中都有效,但我只是想知道:两者中哪一个更有效和/或哪一个更常用?真的有区别吗?
我的 asp.net mvc View 中有以下脚本:- function disableform(id) { $('#' + id).prop("disabled", true); } 但是
我已经在 Oracle VM Ware 中为我的 ubuntu 可信操作系统安装了 visual studio 代码和依赖项。我用这些命令运行代码。 ssh -X myserver code 但是当我
我有这个函数可以切换输入字段的禁用属性: $('.someElement').click(function(){ if (someCondition) { console.log
自从前几天我升级了 angularjs 后,我一直收到警告。每当我打开 ui.bootstrap 模式时,它都会发生。 这是我在 chrome-beta 44 中收到的警告: angular.js:1
我想限制用户在单击特定按钮时在文本框中输入值,否则设置禁用 false。如果我设置 $("#txtquery").attr("disabled","disabled"); 它将文本框设置为空白。如果切
How do I make a Spinner's "disabled" state look disabled? 可能重复. 我尝试了帖子中提到的解决方案,即 ((Spinner) spinner)
这段代码: $tds = $(this).closest('tr').find(td input,select); $tds.attr('disabled','disabled'); 使我的表格行不
使用 jQM 1.4.0我试图覆盖灰色样式(): input[type="text"]:disabled { opacity: 1.0 !important; color: black
不知道为什么这不起作用。 当人们单击我的应用程序的“编辑”按钮时,禁用的文本字段将变为可编辑: $("#bewerken").click(function(e) { $("input[d
我对以下差异有些困惑: swiftlint:disable:next swiftlint:disable:this 最佳答案 它们都用于禁用单行的快速规则。您还可以为单行启用规则。来自 SwiftLi
我看到一些代码 # pylint: disable=W0123 还有一些 # pylint: disable-msg=W0123 它们只是同义词吗? 最佳答案 从 pylint 0.21.0 开始不推
默认情况下,在桌面上,flutter 中的 btns 在禁用时会更改鼠标光标: 我们想禁用此行为,或替换为不同的光标。 最佳答案 要覆盖 ElevatedButton、TextButton 或 Out
我一直在学习很多关于标准 asp.net 验证器的知识,我的最新发现是关于如何禁用验证器客户端,这非常酷。 现在,如果我的初始帖子启用了验证器,但在客户端,我禁用它,服务器端是否识别客户端更改并保留它
默认情况下,在桌面上,flutter 中的 btns 在禁用时会更改鼠标光标: 我们想禁用此行为,或替换为不同的光标。 最佳答案 要覆盖 ElevatedButton、TextButton 或 Out
这个问题在这里已经有了答案: Should I use CSS :disabled pseudo-class or [disabled] attribute selector or is it a
我有一个 python 脚本,它发送包含文本、html 和 ics 附件的多部分电子邮件。这个想法是,现代电子邮件客户端将呈现 HTML 部分并提供将事件添加到用户日历中的功能。 代码如下: impo
我有一个最初被禁用的按钮: Lorem ipsum 对于此按钮,button.getAttribute('disabled') 返回 "disabled"。但是,当我使用 JavaScript 启用此
在我的一些测试中,我必须确认在设置某些标志时某些 select2 下拉菜单被禁用。为了证实这一点,我发现以下策略似乎有效: Assert.True(element.GetAttribute("disa
我是一名优秀的程序员,十分优秀!