@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.action_bar_two_line_text, parent, false); } TwoLineListItem view = (TwoLineListItem) convertView; CharSequence title = mActionBar.getTitle(); view.getText1().setText(title == null ? mTitle : title); view.getText2().setText((CharSequence) getItem(position)); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { Contacts contacts = getItem(position); if (contacts == null) { return null; } // 得到一个LayoutInflater实例 LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); TwoLineListItem view; if (convertView == null) { view = (TwoLineListItem) inflater.inflate(resourceId, parent, false); // 由xml生成View } else { view = (TwoLineListItem) convertView; } if (view.getText1() != null) { view.getText1().setText(contacts.getName()); } if (view.getText2() != null) { view.getText2().setText(contacts.getPhone()); } return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { TwoLineListItem twoLineListItem; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); twoLineListItem = (TwoLineListItem) inflater.inflate(android.R.layout.simple_list_item_2, null); twoLineListItem.getText1().setTextSize(14); twoLineListItem.getText2().setTextSize(12); } else { twoLineListItem = (TwoLineListItem) convertView; } TextView text1 = twoLineListItem.getText1(); TextView text2 = twoLineListItem.getText2(); TrackingData td = (TrackingData) getItem(position); text1.setText(td.toMain()); text2.setText(td.toSub()); return twoLineListItem; }