Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public View getView(int position, View convertView, ViewGroup parent)
- { View v = convertView;
- // A ViewHolder keeps references to children views to avoid unneccessary calls
- // to findViewById() on each row.
- Cursor cursor = getCursor();
- ViewHolder holder;
- cursor.moveToPosition(position);
- // When convertView is not null, we can reuse it directly, there is no need
- // to reinflate it. We only inflate a new View when the convertView supplied
- // by ListView is null.
- if (convertView == null)
- {
- final LayoutInflater inflater = LayoutInflater.from(context);
- convertView = inflater.inflate(mLayout, null);
- // Creates a ViewHolder and store references to the two children views
- // we want to bind data to.
- holder = new ViewHolder();
- holder.iImage = (ImageView)convertView.findViewById(R.id.image);
- holder.tTitle = (TextView) convertView.findViewById(R.id.title);
- holder.tTitle.setFocusable(false);
- convertView.setTag(holder);
- }
- else
- {
- // Get the ViewHolder back to get fast access to the TextView
- // and the ImageView.
- holder = (ViewHolder) convertView.getTag();
- }
- // Bind the data efficiently with the holder.
- String age = cursor.getString(cursor.getColumnIndex(IWebsite.KEY_AGE));
- String city = cursor.getString(cursor.getColumnIndex(IWebsite.KEY_CITY));
- String state = cursor.getString(cursor.getColumnIndex(IWebsite.KEY_STATE));
- String title = cursor.getString(cursor.getColumnIndex(IWebsite.KEY_TITLE));
- String userid = cursor.getString(cursor.getColumnIndex(IWebsite.KEY_USERID));
- String brief = cursor.getString(cursor.getColumnIndex(IWebsite.KEY_BRIEF));
- byte[] blob = cursor.getBlob(cursor.getColumnIndex(IWebsite.KEY_IMAGE));
- Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
- holder.iImage.setImageBitmap(bmp);
- StringBuilder sb = new StringBuilder();
- sb = new StringBuilder();
- sb.append("<html><font size=\"2\" color = #00004a>");
- sb.append("<b>");
- sb.append(title);
- sb.append("</b>");
- sb.append("<br>");
- sb.append("<font size=\"1\" color = #00004a>");
- sb.append(brief);
- sb.append("<br>");
- sb.append("<br>");
- sb.append(userid);
- sb.append(" ");
- sb.append(age);
- sb.append(" ");
- sb.append(city);
- sb.append(" ");
- sb.append(state);
- sb.append("</html>");
- holder.tTitle.setTextSize(11);
- holder.tTitle.setText(Html.fromHtml(sb.toString()));
- v = convertView;
- return v;
- }
- @Override
- public void bindView(View view, Context context, Cursor cursor) {
- }
- @Override
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- // A ViewHolder keeps references to children views to avoid unneccessary calls
- // to findViewById() on each row.
- Cursor c = getCursor();
- ViewHolder holder;
- // When convertView is not null, we can reuse it directly, there is no need
- // to reinflate it. We only inflate a new View when the convertView supplied
- // by ListView is null.
- final LayoutInflater inflater = LayoutInflater.from(context);
- View v = inflater.inflate(mLayout, null);
- // Creates a ViewHolder and store references to the two children views
- // we want to bind data to.
- holder = new ViewHolder();
- holder.iImage = (ImageView)v.findViewById(R.id.image);
- holder.tTitle = (TextView) v.findViewById(R.id.title);
- holder.tTitle.setFocusable(false);
- v.setTag(holder);
- // Bind the data efficiently with the holder.
- String age = c.getString(c.getColumnIndex(IWebsite.KEY_AGE));
- String city = c.getString(c.getColumnIndex(IWebsite.KEY_CITY));
- String state = c.getString(c.getColumnIndex(IWebsite.KEY_STATE));
- String title = c.getString(c.getColumnIndex(IWebsite.KEY_TITLE));
- String userid = c.getString(c.getColumnIndex(IWebsite.KEY_USERID));
- String brief = c.getString(c.getColumnIndex(IWebsite.KEY_BRIEF));
- byte[] blob = c.getBlob(c.getColumnIndex(IWebsite.KEY_IMAGE));
- Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
- holder.iImage.setImageBitmap(bmp);
- StringBuilder sb = new StringBuilder();
- sb = new StringBuilder();
- sb.append("<html><font size=\"2\" color = #00004a>");
- sb.append("<b>");
- sb.append(title);
- sb.append("</b>");
- sb.append("<br>");
- sb.append("<font size=\"1\" color = #00004a>");
- sb.append(brief);
- sb.append("<br>");
- sb.append("<br>");
- sb.append(userid);
- sb.append(" ");
- sb.append(age);
- sb.append(" ");
- sb.append(city);
- sb.append(" ");
- sb.append(state);
- sb.append("</html>");
- holder.tTitle.setTextSize(11);
- holder.tTitle.setText(Html.fromHtml(sb.toString()));
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment