java.lang.StackOverflowError: stack size 8MB while Enabling/Disabling TextView#setTextIsSelectable in ListView Adapter
Finally I got the solution for my problem. I removed ViewHolder
pattern in MyAdapter
like
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[] mItems) {
this.mItems = mItems;
inflater = LayoutInflater.from(context);
}
public void setSelectedPosition(int mSelectedPosition) {
this.mSelectedPosition = mSelectedPosition;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.selectable_text_layout, null, false);
TextView selectableTV = (TextView) convertView.findViewById(R.id.selectableTextView);
selectableTV.setText(getItem(position));
if (position == mSelectedPosition) {
Log.d(TAG, "getView() called with: " + "position = [" + position + "], selected = " + true);
selectableTV.setTextIsSelectable(true);
selectableTV.setSingleLine(false);
selectableTV.setEllipsize(null);
} else {
Log.d(TAG, "getView() called with: " + "position = [" + position + "], selected = " + false);
selectableTV.setTextIsSelectable(false);
selectableTV.setSingleLine(true);
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;
}
}
But still didn't find the the reason for the problem when using ViewHolder
pattern.If anybody find the reason let me know.