Onclick Button In Listview In Android
My project contains listView(homelistView) that contains button(btnList). When I click on button(btnList) it must go to another Activity. I tried a lot but I didn't find a good e
Solution 1:
First remove btnList, btnScan from your MainActivity class.
In your EfficientAdapter class add object Context Context
Change your contructor:
publicEfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
to:
publicEfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.context=context;
}
In your ViewHolder class you need to add Button btnList.
Then in getview method find its view using holder.btnList
Then use:
holder.btnList.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
// TODO Auto-generated method stubIntent next=newIntent(context, SeviceDetails.class);
context.startActivity(next);
}
});
in your getview method before return convertView.
Solution 2:
try this..
@Overridepublic View getView(finalint position, View convertView, ViewGroup parent) {
Viewview= convertView;
if (view == null){
LayoutInflaterinflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.list_layout_ip_addtional_users, null);
}
//Handle TextView and display string from your listTextViewlistItemText2= (TextView)view.findViewById(R.id.list_item_string_name);
listItemText2.setText(list.get(position));
ImageButtonbutton8= (ImageButton) view.findViewById(R.id.ip_additional_user_edit);
button8.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View view) {
Intentintent=newIntent(context, IPAdditionalUsersEdit.class);
context.startActivity(intent);
}
});
return view;
}
Post a Comment for "Onclick Button In Listview In Android"