में सूची दृश्य के अंदर बटन पर ऑनक्लिक श्रोता सेट करें मेरे पास मेरी स्क्रीन में एक सूची दृश्य है, प्रत्येक सूची आइटम में 2 टेक्स्ट व्यू और एक बटन होता है। बटन पर क्लिक करें मैं वेक्टर से कुछ डेटा प्राप्त करने के लिए सूची आइटम चयनित इंडेक्स लेना चाहता हूं।एंड्रॉइड
यह मेरी सूची कस्टम एडाप्टर है। लेकिन मुझे नहीं पता कि यह कैसे करना है।
private class CustomAdapter extends ArrayAdapter<ServicesItems> {
public CustomAdapter(Context context, int resource,
int textViewResourceId, List<ServicesItems> objects) {
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
TextView item = null;
TextView description = null;
Button subNowBtn;
ServicesItems ii = getItem(position);
if (null == convertView) {
convertView = mInflater.inflate(
R.layout.list_of_servics_item_2, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
// cat_name = holder.gettitle();
Resources resources = getResources();
ServicesItems bean1 = (ServicesItems) servicesVector
.elementAt(position);
String cat_name_str = bean1.getService_name().toString();
String descreption = bean1.getDescription().toString();
item = holder.getItem();
item.setText(bean1.getDescription());
description = holder.getDescription();
description.setText(bean1.getService_name());
subNowBtn=holder.getSubButton();
return convertView;
}
private class ViewHolder {
private View mRow;
private TextView description = null;
private TextView item = null;
private Button sub = null;
public ViewHolder(View row) {
mRow = row;
}
public TextView getDescription() {
if (null == description) {
description = (TextView) mRow
.findViewById(R.id.category_tv);
}
return description;
}
public TextView getItem() {
if (null == item) {
item = (TextView)
mRow.findViewById(R.id.descreption_tv);
}
return item;
}
public Button getSubButton(){
if(null==sub){
sub=(Button)findViewById(R.id.subscribe_now_btn);
}
return sub;
}
}
}
मैं इस \t \t \t holder.getSubButton()। SetOnClickListener (नई OnClickListener जोड़ा() \t \t \t { \t \t \t @Override \t \t \t सार्वजनिक शून्य ऑनक्लिक (देखें v) \t \t \t { \t \t \t // तुम क्या चाहते \t \t \t} \t \t \t}); लेकिन यह एक शून्य सूचक exc thorws .. – Reham
मैंने अपना जवाब अपडेट कर दिया है। –
धन्यवाद, यह अब काम करता है। – Reham