I tried to make the onclicklistener function but I get an error on onBindViewHolder
I tried to make a cardview that can be clicked based on the id_daftar, and the database that I use is on the webserver
this is my adapter
import...
import java.util.ArrayList;
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private ArrayList<AndroidVersion> android;
//----------------------------------------------------------------------------------------------
public DataAdapter (ArrayList<AndroidVersion> android){
this.android = android;
}
@NonNull
@Override
public DataAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_row,parent, false);
return new ViewHolder(v);
}
//----------------------------------------------------------------------------------------------
@Override
public void onBindViewHolder(@NonNull DataAdapter.ViewHolder holder,final int position) {
holder.tv_nama_pengusaha.setText(android.get(position).getNama_pengusaha());
holder.tv_nama_usaha.setText(android.get(position).getNama_usaha());
holder.tv_alamat.setText(android.get(position).getAlamat());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(), DetailActivity.class);
i.putExtra("nama_usaha", android.get(position).getNama_usaha());
v.getContext().startActivity(i);
}
});
}
//----------------------------------------------------------------------------------------------
@Override
public int getItemCount() {
return android.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView tv_nama_pengusaha, tv_nama_usaha, tv_alamat, tv_id_daftar, tv_rt,
tv_rw, tv_desa, tv_kecamatan, tv_kategori;
public ViewHolder(@NonNull View itemView) {
super(itemView);
// implement onClick
tv_nama_pengusaha = (TextView)itemView.findViewById(R.id.tv_nama_pengusaha);
tv_nama_usaha = (TextView)itemView.findViewById(R.id.tv_nama_usaha);
tv_alamat = (TextView)itemView.findViewById(R.id.tv_alamat);
}
}
}
this is my DetailActivity
import...
public class DetailActivity extends AppCompatActivity {
TextView detailData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
detailData = findViewById(R.id.tv_nama_usaha);
Intent i = getIntent();
String content = i.getStringExtra("nama_usaha");
detailData.setText(content);
detailData.setMovementMethod(new ScrollingMovementMethod());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
this is the error i got
can someone explain what is the error mean and the solution?
Check to see if all TextViews that are found in the R.layout.card_row
exist and that they have the correct IDs:
tv_nama_pengusaha
tv_nama_usaha
tv_alamat