Issue
I want to remove a particular row from the database as well as from list view when I click the remove button, I tried but I am not getting the error
UserAdapter cannot be cast to android.content.Context
here is my Adapter
public class UserAdapter extends BaseAdapter implements OnTaskCompleted{
Context context;
UserAdapter userAdapter;
Bundle b=new Bundle();
HashMap<Integer, UserSetter> userSettersClassHashMap;
int layoutResId;
String email_id="";
private HashMap<String, String> postDataParams = null;
TextView fname,lname,uname,empid,emailid,contact,role;
Button edit,remove;
public UserAdapter(Context context, HashMap<Integer, UserSetter> userSettersClassHashMap, int layoutResId) {
this.context = context;
this.userSettersClassHashMap = userSettersClassHashMap;
this.layoutResId = layoutResId;
}
@Override
public int getCount() {
return userSettersClassHashMap.size();
}
@Override
public Object getItem(int position) {
return userSettersClassHashMap.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override public View getView(final int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
LayoutInflater lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = lf.inflate(layoutResId, parent, false);
view = convertView;
} else {
view = convertView;
}
fname = (TextView) view.findViewById(R.id.fname);
emailid= (TextView) view.findViewById(R.id.emailid);
role= (TextView) view.findViewById(R.id.role);
remove=(Button) view.findViewById(R.id.remove);
fname.setText(Html.fromHtml(userSettersClassHashMap.get(position).getFirstname()));
role.setText(Html.fromHtml(userSettersClassHashMap.get(position).getRoleName()));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
email_id = String.valueOf(emailid.getText());
Log.v("email adapter", String.valueOf(email_id));
callRemove();
notifyDataSetChanged();
}
public void callRemove() {
postDataParams = new HashMap<>();
postDataParams.put("email_id", email_id);
Log.d("postdataparams","->"+postDataParams);
new WebService(UserAdapter.this, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);
}
});
return view;
}
Solution
Change this line
new WebService(UserAdapter.this, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);
to
new WebService(context, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);
Answered By - Dishonered
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.