当我点击删除按钮时,我想从数据库中删除特定行以及从列表视图中删除,我试过但我没有收到错误
UserAdapter无法转换为android.content.Context
这是我的适配器
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;
}
@覆盖 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;
}
答案 0 :(得分:1)
更改此行
new WebService(UserAdapter.this, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);
到
new WebService(context, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);
答案 1 :(得分:0)
你必须传递上下文而不是USerAdapter.this:
new WebService(context, postDataParams, "RemoveList").execute(AppConstants.BASE_URL + AppConstants.REMOVE_DATA);