public void bindView(View view, Context context, Cursor cursor) { final ViewHolder holder = (ViewHolder) view.getTag(); holder.id = cursor.getLong(holder.idIndex); final Drawable icon = loadIcon(context, cursor, holder); holder.name.setText(cursor.getString(holder.nameIndex)); if (!mIsList) { holder.name.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null); } else { final boolean hasIcon = icon != null; holder.icon.setVisibility(hasIcon ? View.VISIBLE : View.GONE); if (hasIcon) holder.icon.setImageDrawable(icon); if (holder.descriptionIndex != -1) { final String description = cursor.getString(holder.descriptionIndex); if (description != null) { holder.description.setText(description); holder.description.setVisibility(View.VISIBLE); } else { holder.description.setVisibility(View.GONE); } } else { holder.description.setVisibility(View.GONE); } } if (holder.intentIndex != -1) { try { holder.intent = Intent.parseUri(cursor.getString(holder.intentIndex), 0); } catch (URISyntaxException e) { // Ignore } } else { holder.useBaseIntent = true; } }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub index = position; ViewHolder holder = null; JoinCheck info = (JoinCheck) mList.get(position).get(INFO); String icon = info.getTitle(); String result = info.getResult(); String id = info.getCaseid(); String time = info.getTime(); String atm = info.getAtm(); String state = info.getDisplayState(); if (convertView == null) { convertView = mInflater.inflate(R.layout.join_check_listview_item, null); holder = new ViewHolder(); holder.icon = (TextView) convertView.findViewById(R.id.join_check_item_text_icon); holder.id = (TextView) convertView.findViewById(R.id.join_check_item_text_id); holder.result = (TextView) convertView.findViewById(R.id.join_check_item_text_result); holder.atm = (TextView) convertView.findViewById(R.id.join_check_item_text_amt); holder.time = (TextView) convertView.findViewById(R.id.join_check_item_text_time); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.icon.setText(icon); setResultColor(state, result, holder.result); holder.id.setText(id); holder.time.setText(time); holder.atm.setText(atm); return convertView; }
public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.gallery_item, null); holder.imageview = (ImageView) convertView.findViewById(R.id.thumbImage); holder.imageview_checked = (ImageView) convertView.findViewById(R.id.thumbImageChecked); holder.textview = (TextView) convertView.findViewById(R.id.category); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.imageview.setId(position); holder.imageview_checked.setId(position); iv[position] = holder.imageview_checked; holder.imageview.setImageBitmap(thumbnails[position]); holder.imageview_checked.setImageBitmap(thumbnails_checked[position]); holder.textview.setText(categories[position]); if (!thumbnailsselection[position] || position == 0) holder.imageview_checked.setVisibility(View.GONE); holder.id = position; holder.imageview.setOnClickListener( new OnClickListener() { public void onClick(View v) { ImageView cb = (ImageView) v; int id = cb.getId(); if (id == 0) { if (thumbnailsselection[id] == false) { for (int i = 1; i < 9; i++) { iv[i].setVisibility(View.VISIBLE); thumbnailsselection[i] = true; } thumbnailsselection[id] = true; } else { for (int i = 1; i < 9; i++) { iv[i].setVisibility(View.GONE); thumbnailsselection[i] = false; } thumbnailsselection[id] = false; } } else if (thumbnailsselection[id]) { thumbnailsselection[id] = false; iv[id].setVisibility(View.GONE); } else { thumbnailsselection[id] = true; iv[id].setVisibility(View.VISIBLE); } } }); return convertView; }
/** * Make a view to hold each row. * * @see android.widget.ListAdapter#getView(int, android.view.View, android.view.ViewGroup) */ public View getView(final int position, View convertView, ViewGroup parent) { // A ViewHolder keeps references to children views to avoid // unneccessary calls // to findViewById() on each row. // 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) { convertView = mInflater.inflate(R.layout.configuration_spinner_adapter_content, null); // Creates a ViewHolder and store references to the two children // views // we want to bind data to. holder = new ViewHolder(); holder.value = (TextView) convertView.findViewById(R.id.spinner_item_text); // On item click listener /* * convertView.setOnClickListener(new OnClickListener() { * * @Override public void onClick(View v) { * * //TODO Menu instead of check ViewHolder holder = (ViewHolder) * v.getTag(); * * // System.out.print(holder.listEntry.) * * context.entries.get(holder.id).toggleSelected(); // * entries.get(entries.indexOf(holder.listEntry)).toggleSelected(); * //holder.listEntry.toggleSelected(); * holder.checkbox.setChecked(!holder.checkbox.isChecked()); } }); */ convertView.setTag(holder); } else { // Get the ViewHolder back to get fast access to the TextView // and the ImageView. holder = (ViewHolder) convertView.getTag(); } holder.value.setText(context.drinkMixer.getIngredients().get(position).getName()); holder.id = position; return convertView; }
public View getView(int position, View view, ViewGroup parent) { ViewHolder holder; // LayoutInflater inflater = (LayoutInflater) context.getSystemService // (Activity.LAYOUT_INFLATER_SERVICE); if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.pic_and_text_list, parent, false); holder = new ViewHolder(); holder.data = (TextView) view.findViewById(R.id.data); holder.date = (TextView) view.findViewById(R.id.date); holder.id = (TextView) view.findViewById(R.id.id); view.setTag(holder); } else holder = (ViewHolder) view.getTag(); // set textviews and imageview for (int i = 0; i < items.size(); i++) { JSONObject fullContentItem = getItem(position); try { String id = fullContentItem.getString("id"); holder.id.setText("ID: " + id); String data = fullContentItem.getString("data"); holder.data.setText("Data: " + data); String date = fullContentItem.getString("date"); holder.date.setText("Date: " + date); String type = fullContentItem.getString("type"); // if (type.equals("image")) { // Picasso.with(context) // .load(data) // .into(holder.icon); // } // else if (type.equals("text")){ //// homeActivity.addShowHideListener(holder, webViewFragment); // // // // } } catch (JSONException e) { e.printStackTrace(); } } return view; }
public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View hView = convertView; mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (convertView == null) { holder = new ViewHolder(); hView = mInflater.inflate(R.layout.listrow, null); holder.id = (TextView) hView.findViewById(R.id.textView_id); holder.info = (TextView) hView.findViewById(R.id.textView_info); // holder.info = (TextView) hView.findViewById(R.id.info); hView.setTag(holder); } else { holder = (ViewHolder) hView.getTag(); } holder.id.setText(position + ": " + arrayList.get(position)); holder.info.setText(frndarrayList1.get(position)); // ViewHolder holder = (ViewHolder) hView.getTag(); hView.setTag(holder); return hView; }
/** List view preparation */ public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; final RowItem rowItem = (RowItem) getItem(position); convertView = null; if (convertView == null) { LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); convertView = mInflater.inflate(R.layout.commodity_details_row, parent, false); holder = new ViewHolder(); holder.commodityName = (TextView) convertView.findViewById(R.id.commodityname); holder.varietyName = (TextView) convertView.findViewById(R.id.varietyname); holder.date = (TextView) convertView.findViewById(R.id.date); holder.price = (TextView) convertView.findViewById(R.id.price); holder.unit = (TextView) convertView.findViewById(R.id.unit); holder.id = (TextView) convertView.findViewById(R.id.id); holder.mainCategory = (TextView) convertView.findViewById(R.id.mainCategory); holder.unitTagVALue = (TextView) convertView.findViewById(R.id.unitTypeTagValue); holder.offer = (ImageView) convertView.findViewById(R.id.imageoffer); holder.priceHideOrShow = (ImageView) convertView.findViewById(R.id.imageHideShow); holder.commodityImage = (ImageView) convertView.findViewById(R.id.list_commodity_image); holder.discountPrice = (TextView) convertView.findViewById(R.id.discountPrice); holder.quantity = (TextView) convertView.findViewById(R.id.quantity); holder.discountInPercentage = (TextView) convertView.findViewById(R.id.discountInPercentage); typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Sanchez-Regular_0.ttf"); holder.commodityName.setTypeface(typeface); holder.varietyName.setTypeface(typeface); holder.date.setTypeface(typeface); holder.price.setTypeface(typeface); holder.unit.setTypeface(typeface); holder.id.setTypeface(typeface); holder.discountPrice.setTypeface(typeface); holder.quantity.setTypeface(typeface); holder.discountInPercentage.setTypeface(typeface); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } /*try { if (Build.VERSION.SDK_INT >= 16) { userId.setBackground(customBg); password.setBackground(customBg); } else { userId.setBackgroundDrawable(customBg); password.setBackgroundDrawable(customBg); } } catch (Exception e) { Toast.makeText(getActivity(), "Something wrong..", Toast.LENGTH_LONG).show(); }*/ if (rowItem.getStatusPrice() != null && rowItem.getStatusPrice().equalsIgnoreCase("Hide")) { /* holder.priceHideOrShow.setBackground(context.getResources() .getDrawable(R.drawable.hide2));*/ if (Build.VERSION.SDK_INT >= 16) { holder.priceHideOrShow.setBackground(context.getResources().getDrawable(R.drawable.hide2)); } else { holder.priceHideOrShow.setBackgroundDrawable( context.getResources().getDrawable(R.drawable.hide2)); } } else { /*holder.priceHideOrShow.setBackground(context.getResources() .getDrawable(R.drawable.show2));*/ if (Build.VERSION.SDK_INT >= 16) { holder.priceHideOrShow.setBackground(context.getResources().getDrawable(R.drawable.show2)); } else { holder.priceHideOrShow.setBackgroundDrawable( context.getResources().getDrawable(R.drawable.show2)); } } holder.unitTagVALue.setText(rowItem.getUnitTag()); holder.commodityName.setText(rowItem.getCommodityName()); holder.varietyName.setText(rowItem.getVarietyName()); holder.date.setText(rowItem.getDate()); holder.mainCategory.setText(rowItem.getMainCategory()); holder.price.setText(rupeeSymbol + rowItem.getPrice()); holder.unit.setText(rowItem.getUnit()); holder.id.setText(rowItem.getId()); holder.discountPrice.setText(rupeeSymbol + rowItem.getDiscountPrice()); holder.discountInPercentage.setText(rowItem.getDiscountInPercentage() + " %"); if (!rowItem.getDiscountInPercentage().equalsIgnoreCase("No discount")) { holder.price.setPaintFlags(holder.price.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); holder.offer.setVisibility(View.VISIBLE); holder.discountInPercentage.setVisibility(View.VISIBLE); holder.price.setVisibility(View.VISIBLE); } else { holder.price.setPaintFlags(0); holder.offer.setVisibility(View.GONE); holder.price.setVisibility(View.GONE); holder.discountInPercentage.setVisibility(View.GONE); } holder.commodityImage.setTag(rowItem.getImageURL()); BitmapManager.INSTANCE.loadBitmap(rowItem.getImageURL(), holder.commodityImage, 200, 200); holder.priceHideOrShow.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { try { if (rowItem.getStatusPrice().equalsIgnoreCase("Hide")) { listener.DoTaskCompleted( rowItem.getId().toString(), CommodityDetailsActivity.VENDOR_ID, "Show"); } else { listener.DoTaskCompleted( rowItem.getId().toString(), CommodityDetailsActivity.VENDOR_ID, "Hide"); } } catch (Exception e) { e.printStackTrace(); } } }); holder.commodityImage.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (holder.commodityImage != null) { BitmapDrawable drawable = (BitmapDrawable) holder.commodityImage.getDrawable(); Bitmap bitmap = drawable.getBitmap(); maximizeImage(bitmap); } } }); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ViewHolder viewholder = null; if (row == null) { row = LayoutInflater.from(context).inflate(layout, parent, false); viewholder = new ViewHolder(); viewholder.firstLetterView = (TextView) row.findViewById(R.id.id_first_letter); viewholder.imageDefault = (ImageView) row.findViewById(R.id.contact_icon_default); viewholder.contactNumberView = (TextView) row.findViewById(R.id.id_contact_number); viewholder.displayNameView = (TextView) row.findViewById(R.id.id_contact_name); row.setOnClickListener(viewholder.onCheckeClickListener); // viewholder.iOwnerChooseBox.setOnClickListener(viewholder.onCheckeClickListener); row.setTag(viewholder); } else { viewholder = (ViewHolder) row.getTag(); } UtilSetFont.setFontMainScreen(row); CountryItem map = (CountryItem) getItem(position); viewholder.userNumber = map.getNumber(); viewholder.displayName = map.getName(); viewholder.userDisplayNumber = map.getDisplayNumber(); viewholder.id = map.getId(); viewholder.firstLetterView.setVisibility(View.GONE); if (position == 0) { viewholder.firstLetterView.setVisibility(View.VISIBLE); viewholder.firstLetterView.setText("A"); } else { CountryItem map1 = (CountryItem) getItem(position - 1); if (map1.getName().charAt(0) == map.getName().charAt(0)) { viewholder.firstLetterView.setVisibility(View.GONE); } else { viewholder.firstLetterView.setVisibility(View.VISIBLE); viewholder.firstLetterView.setText("" + map.getName().charAt(0)); } } // setProfilePic(viewholder.image, viewholder.imageDefault, viewholder.displayName, // viewholder.userNames); viewholder.displayNameView.setText(viewholder.displayName); viewholder.contactNumberView.setText(viewholder.userDisplayNumber); if (Build.VERSION.SDK_INT >= 16) { Drawable flag = getDrawableFromAsset(viewholder.userNumber + ".png"); // flagName+".png"); if (flag != null) { viewholder.imageDefault.setVisibility(View.VISIBLE); // viewholder.imageDefault.setImageBitmap(flag); viewholder.imageDefault.setBackground(flag); } else { viewholder.imageDefault.setVisibility(View.INVISIBLE); } } else { Bitmap flag = getBitmapFromAsset(viewholder.userNumber + ".png"); // flagName+".png"); if (flag != null) { viewholder.imageDefault.setVisibility(View.VISIBLE); viewholder.imageDefault.setImageBitmap(flag); } else { viewholder.imageDefault.setVisibility(View.INVISIBLE); } } // if(map.getId()!=null){ // Uri u = Uri.parse(map.getId()); // if (u != null) { //// viewholder.imageDefault.setImageURI(u); // viewholder.image.setVisibility(View.VISIBLE); // viewholder.imageDefault.setVisibility(View.GONE); // viewholder.image.setImageURI(u); // } else { // // try{ // String name_alpha = String.valueOf(viewholder.displayName.charAt(0)); // if(viewholder.displayName.contains(" ") && viewholder.displayName.indexOf(' ') < // (viewholder.displayName.length() - 1)) // name_alpha += viewholder.displayName.substring(viewholder.displayName.indexOf(' ') + // 1).charAt(0); // TextDrawable drawable = mDrawableBuilder.build(name_alpha, // mColorGenerator.getColor(viewholder.displayName)); // viewholder.image.setVisibility(View.INVISIBLE); // viewholder.imageDefault.setVisibility(View.VISIBLE); // viewholder.imageDefault.setImageDrawable(drawable); // viewholder.imageDefault.setBackgroundColor(Color.TRANSPARENT); // }catch(Exception ex){ // viewholder.image.setImageResource(R.drawable.avatar); // } // } // }else { // // try{ // String name_alpha = String.valueOf(viewholder.displayName.charAt(0)); // if(viewholder.displayName.contains(" ") && viewholder.displayName.indexOf(' ') < // (viewholder.displayName.length() - 1)) // name_alpha += viewholder.displayName.substring(viewholder.displayName.indexOf(' ') + // 1).charAt(0); // TextDrawable drawable = mDrawableBuilder.build(name_alpha, // mColorGenerator.getColor(viewholder.displayName)); // viewholder.image.setVisibility(View.INVISIBLE); // viewholder.imageDefault.setVisibility(View.VISIBLE); // viewholder.imageDefault.setImageDrawable(drawable); // viewholder.imageDefault.setBackgroundColor(Color.TRANSPARENT); // }catch(Exception ex){ // viewholder.image.setVisibility(View.VISIBLE); // viewholder.image.setImageResource(R.drawable.avatar); // } // } return row; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.post_list_adapter_row, parent, false); viewHolder = new ViewHolder(); viewHolder.name = (TextView) convertView.findViewById(R.id.name); viewHolder.createdTime = (TextView) convertView.findViewById(R.id.createdTime); viewHolder.message = (TextView) convertView.findViewById(R.id.message); viewHolder.picture = (ImageView) convertView.findViewById(R.id.picture); viewHolder.fullPicture = (ImageView) convertView.findViewById(R.id.fullPicture); viewHolder.share = (ImageButton) convertView.findViewById(R.id.btnShare); viewHolder.unlike = (ImageButton) convertView.findViewById(R.id.btnUnLike); viewHolder.like = (ImageButton) convertView.findViewById(R.id.btnLike); viewHolder.comment = (ImageButton) convertView.findViewById(R.id.btnComment); viewHolder.listView = (ListView) convertView.findViewById(R.id.listView2); dataBaseLikeHandler.open(); stringLocalPostLikedMap = dataBaseLikeHandler.returnValue(); viewHolder.share.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager fragmentManager = activity.getFragmentManager(); FacebookSdk.sdkInitialize(activity); ShareDialog shareDialog = new ShareDialog(activity); if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle(postVOs.get((Integer) view.getTag()).getName()) .setContentDescription("Compartido por SwenApp. Buscanos en Google Play") .setContentUrl(Uri.parse(postVOs.get((Integer) view.getTag()).getLink())) .build(); shareDialog.show(linkContent); int points = preferences.getInt("points", 0); points = points + 10; SharedPreferences.Editor editor = preferences.edit(); editor.putInt("points", points); editor.commit(); int share = preferences.getInt("share", 0); share = share + 1; SharedPreferences.Editor editorShare = preferences.edit(); editorShare.putInt("share", share); editorShare.commit(); Desafios desafios = new Desafios(context, preferences, fragmentManager); if ((postVOs .get((Integer) view.getTag()) .getMessage() .contains("#SentiteComodo"))) { int shareSentiteComodo = preferences.getInt("shareSentiteComodo", 0); shareSentiteComodo = shareSentiteComodo + 1; editorShare.putInt("shareSentiteComodo", shareSentiteComodo); } if ((postVOs.get((Integer) view.getTag()).getMessage().contains("#Gifcard"))) { int shareGifCard = preferences.getInt("shareGifCard", 0); shareGifCard = shareGifCard + 1; editorShare.putInt("shareGifCard", shareGifCard); } PerfilFragment.getInstance().setValues(); desafios.getMedallaPorAcciones(); } } }); viewHolder.comment.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager fragmentManager = activity.getFragmentManager(); DialogComment dialogo = new DialogComment(context, postVOs.get((Integer) view.getTag()).getId()); dialogo.show(fragmentManager, "tagAlerta"); reloadListComments(); int points = preferences.getInt("points", 0); points = points + 5; SharedPreferences.Editor editor = preferences.edit(); editor.putInt("points", points); editor.commit(); int comment = preferences.getInt("comment", 0); comment = comment + 1; SharedPreferences.Editor editorComment = preferences.edit(); editorComment.putInt("comment", comment); editorComment.commit(); Desafios desafios = new Desafios(context, preferences, fragmentManager); desafios.getMedallaPorAcciones(); PerfilFragment.getInstance().setValues(); } }); viewHolder.unlike.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { String id = postVOs.get((Integer) view.getTag()).getId(); FragmentManager fragmentManager = activity.getFragmentManager(); viewHolder.unlike.setVisibility(View.GONE); viewHolder.like.setVisibility(View.VISIBLE); Toast.makeText(context, "Me gusta +1", Toast.LENGTH_LONG).show(); if (!stringLocalPostLikedMap.containsKey(id)) { dataBaseLikeHandler.insertData(id, true); } else { LocalPostLiked localPostLiked = stringLocalPostLikedMap.get(id); dataBaseLikeHandler.upDate( localPostLiked.getId(), localPostLiked.getPostID(), true); } int points = preferences.getInt("points", 0); points = points + 1; SharedPreferences.Editor editor = preferences.edit(); editor.putInt("points", points); editor.commit(); int like = preferences.getInt("like", 0); like = like + 1; SharedPreferences.Editor editorLike = preferences.edit(); editorLike.putInt("like", like); editorLike.commit(); stringLocalPostLikedMap = dataBaseLikeHandler.returnValue(); Desafios desafios = new Desafios(context, preferences, fragmentManager); desafios.getMedallaPorAcciones(); PerfilFragment.getInstance().setValues(); } }); viewHolder.like.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { String id = postVOs.get((Integer) view.getTag()).getId(); viewHolder.unlike.setVisibility(View.VISIBLE); viewHolder.like.setVisibility(View.GONE); Toast.makeText(context, "Me gusta -1", Toast.LENGTH_LONG).show(); LocalPostLiked localPostLiked = stringLocalPostLikedMap.get(id); try { dataBaseLikeHandler.upDate( localPostLiked.getId(), localPostLiked.getPostID(), false); } catch (Exception e) { // todo; } stringLocalPostLikedMap = dataBaseLikeHandler.returnValue(); } }); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } PostVO postVO = postVOs.get(position); if (postVO != null) { viewHolder.share.setTag(position); viewHolder.comment.setTag(position); viewHolder.like.setTag(position); viewHolder.unlike.setTag(position); viewHolder.id = postVO.getId(); viewHolder.name.setText(postVO.getName()); viewHolder.createdTime.setText(postVO.getCreatedTime()); viewHolder.message.setText(postVO.getMessage()); Picasso.with(context).load(postVO.getPicture()).into(viewHolder.picture); Picasso.with(context).load(postVO.getFullPicture()).into(viewHolder.fullPicture); if (stringLocalPostLikedMap.containsKey(postVO.getId())) { if (stringLocalPostLikedMap.get(postVO.getId()).isLiked()) { viewHolder.unlike.setVisibility(View.GONE); viewHolder.like.setVisibility(View.VISIBLE); } else { viewHolder.unlike.setVisibility(View.VISIBLE); viewHolder.like.setVisibility(View.GONE); } } else { viewHolder.unlike.setVisibility(View.VISIBLE); viewHolder.like.setVisibility(View.GONE); } if (commentsListMaps.containsKey(postVO.getId())) { List<LocalPostComment> localPostComments = commentsListMaps.get(postVO.getId()); List<String> list = new ArrayList<>(); for (LocalPostComment localPostComment : localPostComments) { list.add(localPostComment.getComment()); } viewHolder.listView.setAdapter( new ArrayAdapter(context, android.R.layout.simple_list_item_1, list)); } else { viewHolder.listView.setAdapter( new ArrayAdapter(context, android.R.layout.simple_list_item_1, new ArrayList())); } } return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder1 = null; ViewHolder holder2 = null; // AVIMTypedMessage message = messageList.get(position); AVIMTextMessage message = (AVIMTextMessage) messageList.get(position); String text; /* Thread t3 = new Thread() { @Override public void run() { try{ bitmapavatal = ImageTools.GetLocalOrNetBitmap(BaseActivity.now_userimgheadurl); } catch(Exception e) { Log.d("image upload ", e.toString()); } } }; t3.start(); */ if (AVIMReservedMessageType.getAVIMReservedMessageType(message.getMessageType()) == AVIMReservedMessageType.TextMessageType) { AVIMTextMessage textMessage = (AVIMTextMessage) message; text = textMessage.getText(); } else { text = message.getContent(); } // Log.v("来源:",message.getFrom()+" 自己:"+selfId+" 信息:"+text); if (message.getFrom().trim().equals(selfId.trim())) { if (convertView == null) { Log.v("设置了自己1", "1"); convertView = LayoutInflater.from(context).inflate(R.layout.list_xx2, null); holder1 = new ViewHolder(); holder1.messageText = (TextView) convertView.findViewById(R.id.list_xx2_text_content); holder1.sender = (TextView) convertView.findViewById(R.id.list_xx2_text_name); holder1.time = (TextView) convertView.findViewById(R.id.list_xx2_text_time); holder1.id = (TextView) convertView.findViewById(R.id.list_xx2_text_id); holder1.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx2_image); convertView.setTag(holder1); } else { Log.v("设置了自己2", "1"); // holder1 = (ViewHolder) convertView.getTag(); convertView = LayoutInflater.from(context).inflate(R.layout.list_xx2, null); holder1 = new ViewHolder(); holder1.messageText = (TextView) convertView.findViewById(R.id.list_xx2_text_content); holder1.sender = (TextView) convertView.findViewById(R.id.list_xx2_text_name); holder1.time = (TextView) convertView.findViewById(R.id.list_xx2_text_time); holder1.id = (TextView) convertView.findViewById(R.id.list_xx2_text_id); holder1.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx2_image); convertView.setTag(holder1); } } else { if (convertView == null) { Log.v("设置了他人1", "1"); convertView = LayoutInflater.from(context).inflate(R.layout.list_xx, null); holder2 = new ViewHolder(); holder2.messageText = (TextView) convertView.findViewById(R.id.list_xx_text_content); holder2.sender = (TextView) convertView.findViewById(R.id.list_xx_text_name); holder2.time = (TextView) convertView.findViewById(R.id.list_xx_text_time); holder2.id = (TextView) convertView.findViewById(R.id.list_xx_text_id); holder2.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx_image); convertView.setTag(holder2); } else { Log.v("设置了他人2", "1"); // holder2 = (ViewHolder) convertView.getTag(); convertView = LayoutInflater.from(context).inflate(R.layout.list_xx, null); holder2 = new ViewHolder(); holder2.messageText = (TextView) convertView.findViewById(R.id.list_xx_text_content); holder2.sender = (TextView) convertView.findViewById(R.id.list_xx_text_name); holder2.time = (TextView) convertView.findViewById(R.id.list_xx_text_time); holder2.id = (TextView) convertView.findViewById(R.id.list_xx_text_id); holder2.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx_image); convertView.setTag(holder2); } } if (AVIMReservedMessageType.getAVIMReservedMessageType(message.getMessageType()) == AVIMReservedMessageType.TextMessageType) { AVIMTextMessage textMessage = (AVIMTextMessage) message; try { text = textMessage.getText().substring(0, textMessage.getText().indexOf("NAME")); } catch (Exception e) { text = textMessage.getText(); } } else { try { text = message.getContent().substring(0, message.getContent().indexOf("NAME")); } catch (Exception e) { text = message.getContent(); } } if (message.getFrom().equals(selfId)) { holder1.messageText.setText(text); holder1.sender.setText("我"); holder1.time.setText("" + Chuli.getNormalTime(message.getTimestamp())); try { if (BaseActivity.bitmapavatal != null) { // Bitmap tempAvatal = ImageTools.GetLocalOrNetBitmap(BaseActivity.now_userimgheadurl); // holder1.avatalurl.setImageBitmap(tempAvatal);//.setImageResource(bitmapavatal); holder1.avatalurl.setImageBitmap( BaseActivity.bitmapavatal); // .setImageResource(bitmapavatal); // Bitmap bitmapAvatal = (Bitmap) message.getAttrs().get("avatal_url"); // holder1.avatalurl.setImageBitmap(bitmapAvatal); } } catch (Exception ee) { Log.v("处理头像 ", ee.toString()); } holder1.id.setText("" + message.getMessageId()); } else { // 遍历学生列表匹配学生名字 设置姓名 try { JSONArray p2 = new JSONArray(BaseActivity.now_studentlist); JSONObject p3; for (int i = 0; i < p2.length(); i++) { p3 = p2.getJSONObject(i); String st = p3.getString("student"); JSONObject p4 = new JSONObject(st); // Log.v("当前ID:",message.getFrom()+":"+p4.getString("client_token")); if (message.getFrom().equals(p4.getString("client_token"))) { fromname = p4.getString("name"); break; } } } catch (Exception e) { e.printStackTrace(); } holder2.messageText.setText(text); holder2.sender.setText(fromname); holder2.time.setText("" + Chuli.getNormalTime(message.getTimestamp())); try { // if(BaseActivity.bitmapavatal!=null){ // holder2.avatalurl.setImageBitmap(BaseActivity.bitmapavatal); String avatalUrl = message.getAttrs().get("avatar_url").toString(); Bitmap tempAvatal = ImageTools.GetLocalOrNetBitmap(avatalUrl); holder2.avatalurl.setImageBitmap(tempAvatal); // holder2.avatalurl.setImageBitmap(); // } } catch (Exception ee) { Log.v("头像 ", ee.toString()); } holder2.id.setText("" + message.getMessageId()); } return convertView; }
@Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = View.inflate(context, R.layout.multieditrow, null); holder.id = (TextView) convertView.findViewById(R.id.id); holder.title = (TextView) convertView.findViewById(R.id.title); holder.have = (CheckBox) convertView.findViewById(R.id.check_have); holder.want = (CheckBox) convertView.findViewById(R.id.check_want); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String id = collections.get(position); holder.id.setText(id); try { JSONObject object = jsonObject.getJSONObject(id); holder.title.setText(object.getString(CollectionAdapter.NAME)); } catch (JSONException e) { holder.title.setText("unknown"); e.printStackTrace(); } holder.have.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { CheckBox box = (CheckBox) v; if (box.isChecked()) { checked[position] += HAVE; } else { checked[position] -= HAVE; } } }); holder.want.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { CheckBox box = (CheckBox) v; if (box.isChecked()) { checked[position] += WANT; } else { checked[position] -= WANT; } } }); if (checked[position] == BOTH) { holder.have.setChecked(true); holder.want.setChecked(true); } else if (checked[position] == WANT) { holder.want.setChecked(true); holder.have.setChecked(false); } else if (checked[position] == HAVE) { holder.have.setChecked(true); holder.want.setChecked(false); } else { holder.have.setChecked(false); holder.want.setChecked(false); } return convertView; }