json 형식으로 내 서버에서 데이터를 가져옵니다. 내 Listview
에 데이터를 전달하고 내가 TAG_CONFIRMATION
의 데이터를 읽을 수서버 데이터를 사용하여 사용자 정의 어댑터 단일 행 변경을 사용하는 Android ListView
public class AppointmentAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
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(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.appointments_list_item, null);
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);
ImageView new_appointment = (ImageView)vi.findViewById(R.id.new_appointment);
//CheckBox check = (CheckBox)vi.findViewById(R.id.tododone); // checkbox
HashMap<String, String> todo = new HashMap<String, String>();
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 = confirmation.getText().toString();
//Log.d("CONFIRMATION: ", confirmation);
if (confirmation.getText().toString().equals("pending")){
Log.d("PASS CONFIRMATION: ", confirmation.getText().toString());
new_appointment.setVisibility(View.VISIBLE);
}
return vi;
}
}
아래의 사용자 정의 어댑터를 사용하여 내 목록을 만들고이의 특정 행에 Imageview
에 볼 수 설정 "pending"
동일한 경우 내 Listview
. 그러나 Imageview
은 모든 행에서 사용 가능합니다. 내 코드에서 무엇을 변경해야합니까? 그리고 Listview
에서 특정 행 하나만 맞춤 설정하는 방법은 무엇입니까?
어댑터의 기본 데이터가 변경되면 'notifiyDatasetChanged'를 사용하여 목록이 새 데이터로 업데이트되도록해야합니다. – tyczj
하지만 내 데이터를 가져 오는 순간부터 초기화하고 싶습니다. 목록보기. – appLogic
실제로 왜'View vi = convertView;'를하고 있는지 알고 계십니까? – njzk2