我试图通过在回调函数中传递视图来在另一个类中累积我的recyclerview视图符号的值。在运行时,我可以看到具有其值的项目,但如何从视图持有者中提取这些值?我想在回调方法中提取textview值。我如何实现这一目标?
这是我的观察者类
的实现public class CommentViewHolder : RecyclerView.ViewHolder, IItemTouchHelperViewHolder
{
public TextView username;
public ImageView userphoto;
public TextView time;
public TextView comment;
public View _itemView;
public CommentViewHolder(View view)
: base(view)
{
_itemView = view;
}
public void OnItemClear()
{
_itemView.SetBackgroundColor(Color.White);
}
public void OnItemSelected()
{
_itemView.SetBackgroundColor(Color.LightGray);
}
}
这是获取视图的回调方法。
public override int GetMovementFlags(Android.Support.V7.Widget.RecyclerView recyclerView, Android.Support.V7.Widget.RecyclerView.ViewHolder viewHolder)
{
if (recyclerView.GetLayoutManager() is GridLayoutManager)
{
//do something
}
else
{
//do something
}
}
答案 0 :(得分:1)
看起来回调会为您提供ViewHolder
,因此您应该能够通过提供的ViewHolder
获取值:
if(viewHolder instanceof CommentViewHolder) {
CommentViewHolder holder = (CommentViewHolder) viewHolder;
String username = holder.username.getText();
}