我有一个按钮对象,我想让它可以点击并启动一个新的Intent。数组列表中的按钮布局很好,但是当我尝试添加on click listenter时,它会出现问题“尝试调用虚方法”void android.widget.Button.setOnClickListener(android.view.View $ OnClickListener )'在空对象引用上“
这是我的代码:
public class PhotoshootAdapter extends ArrayAdapter{
private List<Photoshoots> photoshootsscheduleList;
private int resource;
private LayoutInflater inflater;
public PhotoshootAdapter(Context context, int resource, List<Photoshoots> objects) {
super(context, resource, objects);
photoshootsscheduleList = objects;
this.resource = resource;
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(resource, null);
}
Button btnPhotoshoot;
btnPhotoshoot = (Button)findViewById(R.id.btnPhotoshoot);
TextView tvPotential;
TextView tvAddress;
TextView tvDateofShoot;
tvPotential = (TextView) convertView.findViewById(R.id.tvPotential);
tvAddress = (TextView) convertView.findViewById(R.id.tvAddress);
tvDateofShoot = (TextView)convertView.findViewById(R.id.tvDateofShoot);
StringBuffer potentialBuffer = new StringBuffer();
for(Photoshoots.potentialDetails details : photoshootsscheduleList.get(position).getPotentialDetails()){
potentialBuffer.append(details.getPotentialName() + "\n");
}
StringBuffer addressBuffer = new StringBuffer();
for(Photoshoots.addressDetails details : photoshootsscheduleList.get(position).getAddressDetails()){
addressBuffer.append(details.getAddress() + "\n");
}
StringBuffer dateBuffer = new StringBuffer();
for(Photoshoots.dateDetails details : photoshootsscheduleList.get(position).getDateDetails()){
dateBuffer.append(details.getDateofShoot());
}
final StringBuffer potentialIDBuffer = new StringBuffer();
for(Photoshoots.PotentialIDDetails details : photoshootsscheduleList.get(position).getPotentialIDDetails()){
potentialIDBuffer.append(details.getPotentialIDDetails());
}
tvPotential.setText(potentialBuffer.toString());
tvAddress.setText(addressBuffer.toString());
tvDateofShoot.setText(dateBuffer.toString());
btnPhotoshoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ShowPhotoshootList.this, schedule_my_photoshoot.class);
intent.putExtra("PotentialID", potentialIDBuffer.toString());
}
});
return convertView;