Ich habe eine Arraylist mit Objekten .
Leider finde ich keine Möglichkeit, entweder die Klasse oder die Pos(index) des gerade gewählten Items zu ermitteln.
Hat jemand eine Idee wie man das anstellen muss.
Leider finde ich keine Möglichkeit, entweder die Klasse oder die Pos(index) des gerade gewählten Items zu ermitteln.
Hat jemand eine Idee wie man das anstellen muss.
Code:
package com.job.vt;
import android.provider.ContactsContract;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.textfield.TextInputLayout;
import java.util.ArrayList;
public class A1000_VokTestRCAdapter extends RecyclerView.Adapter<A1000_VokTestRCAdapter.rc_a1000_rcviewholder> {
private ArrayList<A1000_VokTestDataClass> voktestdata;
public class rc_a1000_rcviewholder extends RecyclerView.ViewHolder{
public TextView baselanguage;
public TextView word;
public TextInputLayout usersinput;
public EditText usersimput_edittext;
public ImageButton showword;
public ImageButton playsound;
public rc_a1000_rcviewholder(@NonNull final View itemView) {
super ( itemView );
word = itemView.findViewById ( R.id.a1000_word );
baselanguage = itemView.findViewById ( R.id.a1000_baselanguage );
usersinput = itemView.findViewById ( R.id.a1000_usersinput );
usersimput_edittext = itemView.findViewById ( R.id.a1000_usersinput_edittxt );
showword = itemView.findViewById ( R.id.a1000_showword );
playsound = itemView.findViewById ( R.id.a1000_playsound );
usersimput_edittext.setOnFocusChangeListener(new View.OnFocusChangeListener () {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// Aber wie komme ich an die Position
// A1000_VokTestDataClass currentdata = voktestdata.get(position);
Log.d ( "voktest" , "jetzt würde ich speichern : " + usersimput_edittext.getText ( ) + "index : " );
}
}
});
showword.setOnClickListener ( new View.OnClickListener ( ) {
@Override
public void onClick(View view) {
Log.d ("voktest", "Show was clicked !");
}
} );
playsound.setOnClickListener ( new View.OnClickListener ( ) {
@Override
public void onClick(View view) {
Log.d ("voktest", "Sound was clicked !");
}
} );
}
}
public A1000_VokTestRCAdapter(ArrayList<A1000_VokTestDataClass> testdatafromdb) {
voktestdata = testdatafromdb;
}
@NonNull
@Override
public rc_a1000_rcviewholder onCreateViewHolder(@NonNull ViewGroup parent , int viewType) {
View v = LayoutInflater.from(parent.getContext ()).inflate ( R.layout.activity_a1000_voktest_recyclerview, parent,false );
rc_a1000_rcviewholder vh = new rc_a1000_rcviewholder ( v );
return vh;
}
@Override
public void onBindViewHolder(@NonNull rc_a1000_rcviewholder holder , int position) {
A1000_VokTestDataClass currentdata = voktestdata.get(position);
holder.baselanguage.setText (currentdata.getBaselanguage ());
holder.word.setText ( currentdata.getWord () );
}
@Override
public int getItemCount() {
return voktestdata.size ();
}
private void SafeUsersInput (String strusersinput) {
// A1000_VokTestDataClass currentdata = voktestdata
// currentdata.setUsersinput ( strusersinput );
}
}