gol*_*har 3 java android textview android-recyclerview
这是我的适配器RecyclerView.我怎样才能获得deckName另一项活动的价值?
public class ViewHolder extends RecyclerView.ViewHolder {
public RelativeLayout deckLayout;
public LinearLayout countsLayout;
public ImageButton deckExpander;
public ImageButton indentView;
public TextView deckName;
public TextView deckNew, deckLearn, deckRev;
public ViewHolder(View v) {
super(v);
deckLayout = (RelativeLayout) v.findViewById(R.id.DeckPickerHoriz);
countsLayout = (LinearLayout) v.findViewById(R.id.counts_layout);
deckExpander = (ImageButton) v.findViewById(R.id.deckpicker_expander);
indentView = (ImageButton) v.findViewById(R.id.deckpicker_indent);
deckName = (TextView) v.findViewById(R.id.deckpicker_name);
deckNew = (TextView) v.findViewById(R.id.deckpicker_new);
deckLearn = (TextView) v.findViewById(R.id.deckpicker_lrn);
deckRev = (TextView) v.findViewById(R.id.deckpicker_rev);
}
}
Run Code Online (Sandbox Code Playgroud)
我想获取此值并将其与字符串进行比较:
final int itemCount = mDeckListAdapter.getItemCount();
DeckAdapter a = new DeckAdapter(getLayoutInflater(), getApplicationContext());
for(int i=0;i<itemCount;i++){
// final CharSequence text = DeckAdapter.ViewHolder.deckName.getText();
if (text.equals(di)){
mRecyclerView.findViewHolderForAdapterPosition(i).itemView.performClick();
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码并没有真正起作用.
Sri*_*nth 14
试试这个
String title = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)).getText().toString();
Run Code Online (Sandbox Code Playgroud)
我喜欢用过
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
// String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String title1 = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)).getText().toString();
Toast.makeText(getApplicationContext(), title1, Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClick(View view, int position) { }
}));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8502 次 |
| 最近记录: |