【发布时间】:2015-03-16 05:32:57
【问题描述】:
您好,我从服务器获取数据并将它们传递到我的自定义适配器中以填充我的 ListView。以下是我的自定义适配器代码:
public class AppointmentAdapter extends BaseAdapter {
private AppointmentAdapter adapter;
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
HashMap<String, String> todo = new HashMap<String, String>();
// String confirmation;
RelativeLayout confirm_corner;
public AppointmentAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
//View vi=convertView;
//if(convertView==null)
final View vi = inflater.inflate(R.layout.appointments_list_item, null);
adapter = new AppointmentAdapter(activity,data);
TextView aid = (TextView)vi.findViewById(R.id.aid); // id
TextView apptitle = (TextView)vi.findViewById(R.id.apptitle); // title
TextView starts_date = (TextView)vi.findViewById(R.id.starts_date); // created_at
TextView starts_time = (TextView)vi.findViewById(R.id.starts_time);
TextView contact = (TextView)vi.findViewById(R.id.contact);
TextView confirmation = (TextView)vi.findViewById(R.id.confirmation);
confirm_corner = (RelativeLayout)vi.findViewById(R.id.confirm_corner);
//CheckBox check = (CheckBox)vi.findViewById(R.id.tododone); // checkbox
todo = data.get(position);
// Setting all values in listview
aid.setText(todo.get(AppointmentsFragment.TAG_AID));
apptitle.setText(todo.get(AppointmentsFragment.TAG_APPTITLE));
starts_date.setText(todo.get(AppointmentsFragment.TAG_STARTDATE));
starts_time.setText(todo.get(AppointmentsFragment.TAG_STARTTIME));
contact.setText(todo.get(AppointmentsFragment.TAG_CONTACT));
confirmation.setText(todo.get(AppointmentsFragment.TAG_CONFIRMATION));
String test = todo.get(AppointmentsFragment.TAG_USER_EMAIL);
//Handle buttons and add onClickListeners
ImageView accept = (ImageView)vi.findViewById(R.id.accept);
ImageView deny = (ImageView)vi.findViewById(R.id.deny);
//String test = confirmation.getText().toString();
//&& (!test.equals(MainActivity.user_email))
Log.d("CONFIRMATION: ", MainActivity.user_email);
if (confirmation.getText().toString().equals("pending") ){
Log.d("PASS CONFIRMATION: ", confirmation.getText().toString());
confirm_corner.setVisibility(View.VISIBLE);
}
accept.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//do something
confirm_corner = (RelativeLayout)vi.findViewById(R.id.confirm_corner);
Log.d("Button accept: ", MainActivity.user_email);
new Confirm_appointment().execute();
//vi.setBackgroundColor(Color.RED);
confirm_corner.setVisibility(View.GONE);
}
});
deny.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//do something
Log.d("Button deny: ", MainActivity.user_email);
new Deny_appointment().execute();
confirm_corner.setVisibility(View.INVISIBLE);
//adapter = new AppointmentAdapter(this,data);
data.remove(position);
data.clear();
data.addAll(data);
adapter.notifyDataSetChanged();
}
});
return vi;
}
我希望当我单击拒绝按钮时要删除该行。我应该在我的代码中更改什么来解决这个问题?
【问题讨论】:
标签: android listview android-listview arraylist android-custom-view