【发布时间】:2018-01-04 13:21:27
【问题描述】:
我想在 recyclerview 中同时显示 html 文本和图像,但我猜我做不到。当我习惯了一个按钮时,它就可以工作了。但是我尝试使用 recyclerview 它不起作用。有人帮我吗?同时我在android上也太新手了。 谢谢大家。
public MyViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View position) {
int mposition = getLayoutPosition();
callActivities(mposition);
}
private void callActivities(int mposition) {
if (mposition == 0) {
image.setImageResource(R.drawable.bb);
String htmlAsString = getString(R.string.bb);
Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
vh= (TextView) findViewById(R.id.vh);
vh.setText(htmlAsSpanned);
((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE); ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
} else if (mposition == 1){
image.setImageResource(R.drawable.db);
String htmlAsString = getString(R.string.db);
Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
vh= (TextView) findViewById(R.id.vh);
vh.setText(htmlAsSpanned);
((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE); ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
} else if (mposition == 2){
image.setImageResource(R.drawable.cb);
String htmlAsString = getString(R.string.cb);
Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
vh= (TextView) findViewById(R.id.vh);
vh.setText(htmlAsSpanned);
((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE); ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
} ((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE); ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
}
}
});
}
}
【问题讨论】:
-
你介意编辑这个问题,尤其是源代码。
-
getLayoutPosition() 有什么不同?
-
愿这个帮助你link
-
我在我的 recyleview 上有三个项目,然后当我单击其中一个时。我想在drawable中显示我的图像并在字符串文件中显示我的html文本。有可能吗?
-
发布方法getLayoutPosition()
标签: android android-recyclerview textview imageview