该解决方案无效,建议在任何条件下均能正常工作的任何解决方案 或其他行为也说明了如何仅将第一项值转换为字符串以进一步用于列表代码视图。
@Override
public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) {
// cvChipsRecycler chipsRecycler = (cvChipsRecycler) listRecyclerItem.get(position);
holder.name.setText(listRecyclerItem.get(position));
if (selected_position == position) {
holder.cvLayout.setBackgroundResource(R.drawable.cv_recycler_layout_clicked_round_background);
holder.name.setTextColor(Color.BLACK);
}else {
holder.cvLayout.setBackgroundResource(R.drawable.abc_round_cornor_grey);
holder.name.setTextColor(context.getResources().getColor(R.color.xyz_white,context.getTheme()));
}
holder.name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selected_position = position;
try {
String stName = (String) holder.name.getText();
InputStream is = context.getAssets().open(childName.toLowerCase() + "/" + stName.toLowerCase());
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String text = new String(buffer);
final View rootView = ((cdCodeViewer) context).getWindow().getDecorView().findViewById(android.R.id.content);
CodeView cv = (CodeView) rootView.findViewById(R.id.cv_code_viewer);
cv.setTheme(CodeViewTheme.DARKULA).fillColor();
cv.showCode(text);
android.widget.LinearLayout codeViewLayout = (android.widget.LinearLayout) cv.getParent();
codeViewLayout.setPadding(8, 8, 8, 8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}