0
因此,在我的recyclerview項目中,我允許用戶在eddittext和textview之間切換。它可以在回收站視圖的第一個位置完全處理項目,在第二個位置它只會切換編輯文本但不切換回文本視圖。然而,刪除選項適用於所有職位。這是我的recyclerview加墨機RecyclerView操作只能編輯第一個位置上的工作?
package com.intellidev.mobitranscribe;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import java.util.ArrayList;
public class NoteItemAdapter extends RecyclerView.Adapter<NoteItemHolder> {
private ArrayList<NoteItem> noteItems;
private String[] mNoteItemArray;
private AppCompatActivity context;
public NoteItemAdapter(ArrayList<NoteItem> noteItemArrayList, AppCompatActivity Context) {
this.noteItems = noteItemArrayList;
this.context = Context;
}
@Override
public NoteItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new NoteItemHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.note_item, parent, false));
}
@Override
public void onBindViewHolder(final NoteItemHolder holder, int position) {
final NoteItem noteItem = this.noteItems.get(position);
holder.imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NoteItemHolder h = holder;
showTextOptions(h, noteItem);
}
});
holder.textView.setText(noteItem.getMessage());
if (!holder.textViewSpeaker.getText().toString().isEmpty()){
holder.textViewSpeaker.setText(noteItem.getSpeaker());
}
}
private void showTextOptions(final NoteItemHolder holder, final NoteItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialogTheme);
builder.setItems(R.array.noteTextSelectionItems, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.e("tree","it is "+i);
if (i==0) {
//reference picture
}else if (i==1) {
// reference webdocument or link
} else if (i==2) {
NoteItemHolder h = holder;
switchViews(h, item);
} else if (i==3) {
//delete the text
int n = noteItems.indexOf(item);
noteItems.remove(n);
notifyDataSetChanged();
}
}
}).show();
}
@Override
public int getItemCount() {
return this.noteItems.size();
}
protected void switchViews(NoteItemHolder h, NoteItem note) {
if (context.findViewById(R.id.noteItemTextView).getVisibility()==View.GONE) {
//EditText editText = (EditText) context.findViewById(R.id.noteItemEditText);
String x = h.editText.getText().toString();
h.editText.setVisibility(View.GONE);
//TextView textView = (TextView) context.findViewById(R.id.noteItemTextView);
h.textView.setText(x);
h.textView.setVisibility(View.VISIBLE);
} else {
// TextView textView = (TextView) context.findViewById(R.id.noteItemTextView);
String x = h.textView.getText().toString();
h.textView.setVisibility(View.GONE);
//EditText editText = (EditText) context.findViewById(R.id.noteItemEditText);
h.editText.setText(x);
h.editText.setVisibility(View.VISIBLE);
}
}
}