@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; }
/** * This is called to render a particular item for the on screen list. Uses an off-the-shelf * TwoLineListItem view, which contains text1 and text2 TextViews. We pull data from the RssItem * and set it into the view. The convertView is the view from a previous getView(), so we can * re-use it. * * @see ArrayAdapter#getView */ @Override public View getView(int position, View convertView, ViewGroup parent) { TwoLineListItem view; // Here view may be passed in for re-use, or we make a new one. if (convertView == null) { view = (TwoLineListItem) mInflater.inflate(android.R.layout.simple_list_item_2, null); } else { view = (TwoLineListItem) convertView; } RssItem item = this.getItem(position); view.getText1().setText(item.getTitle()); return view; }
@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; }