내 앱은 두 개의 조각으로 구성됩니다 (A와 B라고하겠습니다). 조각 A는 RecyclerView를 표시하고 조각 B는 해당 Recycler에서 선택한 항목의 콘텐츠를 보여줍니다. 작은 화면과 일반 화면에서는 각 프래그먼트가 활동에 표시되지만 큰 화면에서는 두 프래그먼트가 동시에 표시되므로 사용자가 RecyclerView에서 항목을 클릭하면 강조 표시되는 다중 창 활동을 원합니다. StackOverflow에서 이와 같은 많은 질문을 찾았지만 내 어댑터에서 작동하지 않습니다.
final FragmentCallback activity;
final FragmentA fragment; //The fragment with the RecyclerView
Cursor cursor;
int idColumnIndex;
int titleColumnIndex;
int balanceColumnIndex;
public MoneyboxesAdapter(FragmentCallback activity, FragmentA frag){
this.activity = activity;
this.fragment = frag;
}
public void swapCursor(Cursor c){
// Method called whenever the data stored on the DB has changed
this.cursor = c; //Updates the current cursor
if(cursor!=null){
cursor.moveToFirst();
idColumnIndex = cursor.getColumnIndex(MoneyboxProvider.COLUMN_MONEYBOX_ID);
titleColumnIndex = cursor.getColumnIndex(MoneyboxProvider.COLUMN_MONEYBOX_TITLE);
balanceColumnIndex = cursor.getColumnIndex(MoneyboxProvider.COLUMN_MONEYBOX_BALANCE);
}
notifyDataSetChanged();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
CardView v = (CardView) LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.moneybox_item, viewGroup, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
// Sets up the views
cursor.moveToPosition(i);
final long id = getItemId(i);
final String moneyboxTitle = cursor.getString(titleColumnIndex);
final float balance = cursor.getFloat(balanceColumnIndex);
viewHolder.title.setText(moneyboxTitle);
viewHolder.balance.setText(balance);
viewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.onLoadMoneybox(id);
//TODO: Show selected on multipane
}
});
}
@Override
public int getItemCount() {
return cursor!=null?cursor.getCount():0;
}
public long getItemId(int position){
// Gets the ID in the DB of a moneybox
cursor.moveToPosition(position);
return cursor.getLong(idColumnIndex);
}
static class ViewHolder extends RecyclerView.ViewHolder{
CardView cardView;
TextView title;
TextView balance;
ImageView threeDots;
public ViewHolder(CardView itemView) {
super(itemView);
cardView = itemView;
title = (TextView) itemView.findViewById(R.id.moneybox_item_title);
balance = (TextView) itemView.findViewById(R.id.moneybox_item_balance);
threeDots = (ImageView)itemView.findViewById(R.id.three_dots_moneybox);
}
}
목록 항목에 대한 선택기를 만들고 view.setSelected (true); 선택한 특정 위치에 대해 선택하고 마지막으로 선택한보기를 추적하고 사용자가 새 행 항목을 클릭하면 false로 설정합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다