我不明白什么是转换视图。具体来说,程序何时进入 if 条件以及何时进入 else 条件?
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
LayoutInflater mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.data, parent, false);
holder = new ViewHolder();
holder.txtDesc = convertView.findViewById(R.id.txtDesc);
holder.txtSubject = convertView.findViewById(R.id.txtSubject);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtDesc.setText(profileListView.get(position).getName());
holder.txtSubject.setText(profileListView.get(position).getEmail());
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, profileListView.get(position).getName()+"hi go to detail page", Toast.LENGTH_SHORT).show();
}
});
return convertView;
}