答案 0 :(得分:1)
最接近公共API的是逐个弹出所有元素:
// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if(listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
// Get the {@link AndroidFlavor} object located at this position in the list
Record currentRecord = getItem(position);
//listItemView.setBackgroundResource(R.drawable.customshape);
// Find the TextView in the list_item.xml layout with the ID version_name
TextView nameTextView = (TextView) listItemView.findViewById(R.id.record_name);
// Get the version name from the current AndroidFlavor object and
// set this text on the name TextView
nameTextView.setText(currentRecord.getmName());
nameTextView.setTextSize(15);
nameTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.colorTitle));
ImageView imageViewMiniatura = (ImageView) listItemView.findViewById(R.id.imageViewMiniatura);
UrlImageViewHelper.setUrlDrawable(imageViewMiniatura, currentRecord.getmThumbnailUrl());
View termometherIndicatorView = (View) listItemView.findViewById(R.id.termometherIndicator);
switch(currentRecord.getmSellerReputation()){ // ta dando problema de nullPointer aleatóriamente
case "1_red":
termometherIndicatorView.setBackgroundColor(0xFFF4111C);
break;
case "2_orange":
termometherIndicatorView.setBackgroundColor(0xFFFF8000);
break;
case "3_yellow":
termometherIndicatorView.setBackgroundColor(0xFFFFF059);
break;
case "4_light_green":
termometherIndicatorView.setBackgroundColor(0xFFD6F076);
break;
case "5_green":
termometherIndicatorView.setBackgroundColor(0xFF00B200);
break;
default:
termometherIndicatorView.setBackgroundColor(0xFFF4F4F4);
}
// Find the TextView in the list_item.xml layout with the ID version_number
TextView numberTextView = (TextView) listItemView.findViewById(R.id.record_price);
// Get the version number from the current AndroidFlavor object and
// set this text on the number TextView
numberTextView.setText(converterDoubleEmReais(currentRecord.getmPrice()));
numberTextView.setTextSize(20);
numberTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.colorPrice));
TextView textViewPrecoComTabela = (TextView) listItemView.findViewById(R.id.preco_com_tabela);
ImageView imageViewPrecoComSedex = (ImageView) listItemView.findViewById(R.id.preco_com_sedex);
ImageView imageViewPrecoComPac = (ImageView) listItemView.findViewById(R.id.preco_com_pac);
ImageView imageViewPrecoComExpresso = (ImageView) listItemView.findViewById(R.id.preco_com_menvios_expresso);
ImageView imageViewPrecoComNormal = (ImageView) listItemView.findViewById(R.id.preco_com_menvios_normal);
TextView textViewPrecoComSedex = (TextView) listItemView.findViewById(R.id.preco_com_sedex_text_view);
TextView textViewPrecoComPac = (TextView) listItemView.findViewById(R.id.preco_com_pac_text_view);
TextView textViewPrecoComExpresso = (TextView) listItemView.findViewById(R.id.preco_com_menvios_expresso_text_view);
TextView textViewPrecoComNormal = (TextView) listItemView.findViewById(R.id.preco_com_menvios_normal_text_view);
LinearLayout linearLayoutPrecoComSedex = (LinearLayout) listItemView.findViewById(R.id.preco_sedex_layout);
LinearLayout linearLayoutPrecoComPac = (LinearLayout) listItemView.findViewById(R.id.preco_pac_layout);
LinearLayout linearLayoutPrecoComExpresso = (LinearLayout) listItemView.findViewById(R.id.preco_menvios_expresso_layout);
LinearLayout linearLayoutPrecoComNormal = (LinearLayout) listItemView.findViewById(R.id.preco_menvios_normal_layout);
TextView sellerLocationTextView = (TextView) listItemView.findViewById(R.id.seller_location);
sellerLocationTextView.setText("(" + currentRecord.getmSellerLocation().toString() + ")");
/**TextView anuncioStartDateTextView = (TextView) listItemView.findViewById(R.id.anuncio_start_date);
DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
Date dataAnuncio = currentRecord.getmAnuncioId();
String dataEmString = df.format(dataAnuncio);
anuncioStartDateTextView.setText(dataEmString);**/
ImageView freeShippingImageView = (ImageView) listItemView.findViewById(R.id.imageViewFreteGratis);
if (currentRecord.ismFreeShipping()) {
freeShippingImageView.setVisibility(View.VISIBLE);
} else {
freeShippingImageView.setVisibility(View.GONE);
}
if(currentRecord.getmShippingMode().equals("custom")) {
textViewPrecoComTabela.setText("Tabelado: " + converterDoubleEmReais(currentRecord.getmMercadoLivreCustomPrice()) + "(" + converterDoubleEmReais(currentRecord.getmMercadoLivreCustomPrice() + currentRecord.getmPrice()) + ")");
textViewPrecoComExpresso.setText("");
textViewPrecoComNormal.setText("");
textViewPrecoComPac.setText("");
textViewPrecoComSedex.setText("");
linearLayoutPrecoComSedex.setVisibility(View.GONE);
linearLayoutPrecoComPac.setVisibility(View.GONE);
linearLayoutPrecoComExpresso.setVisibility(View.GONE);
linearLayoutPrecoComNormal.setVisibility(View.GONE);
} else if(currentRecord.getmShippingMode().equals("not_specified")) {
textViewPrecoComSedex.setText(converterDoubleEmReais(currentRecord.getmPrecoSedex()) + "(" + converterDoubleEmReais(currentRecord.getmPrecoSedex() + currentRecord.getmPrice()) + ")");
textViewPrecoComPac.setText(converterDoubleEmReais(currentRecord.getmPrecoPac()) + "(" + converterDoubleEmReais(currentRecord.getmPrecoPac() + currentRecord.getmPrice()) + ")");
// Find the ImageView in the list_item.xml layout with the ID list_item_icon
//ImageView iconView = (ImageView) listItemView.findViewById(R.id.list_item_icon);
// Get the image resource ID from the current AndroidFlavor object and
// set the image to iconView
//iconView.setImageResource(currentRecord.getImageResourceId());
textViewPrecoComExpresso.setText("");
textViewPrecoComNormal.setText("");
textViewPrecoComTabela.setText("");
linearLayoutPrecoComSedex.setVisibility(View.VISIBLE);
linearLayoutPrecoComPac.setVisibility(View.VISIBLE);
linearLayoutPrecoComExpresso.setVisibility(View.GONE);
linearLayoutPrecoComNormal.setVisibility(View.GONE);
} else if(currentRecord.getmShippingMode().equals("me1") || currentRecord.getmShippingMode().equals("me2")) {
textViewPrecoComExpresso.setText(converterDoubleEmReais(currentRecord.getmMercadoEnviosExpresso()) + "(" + converterDoubleEmReais(currentRecord.getmMercadoEnviosExpresso() + currentRecord.getmPrice()) + ")");
textViewPrecoComNormal.setText(converterDoubleEmReais(currentRecord.getmMercadoEnviosNormal()) + "(" + converterDoubleEmReais(currentRecord.getmMercadoEnviosNormal() + currentRecord.getmPrice()) + ")");
// Find the ImageView in the list_item.xml layout with the ID list_item_icon
//ImageView iconView = (ImageView) listItemView.findViewById(R.id.list_item_icon);
// Get the image resource ID from the current AndroidFlavor object and
// set the image to iconView
//iconView.setImageResource(currentRecord.getImageResourceId());
textViewPrecoComPac.setText("");
textViewPrecoComSedex.setText("");
textViewPrecoComTabela.setText("");
linearLayoutPrecoComExpresso.setVisibility(View.VISIBLE);
linearLayoutPrecoComNormal.setVisibility(View.VISIBLE);
linearLayoutPrecoComSedex.setVisibility(View.GONE);
linearLayoutPrecoComPac.setVisibility(View.GONE);
} else {
textViewPrecoComExpresso.setText("");
textViewPrecoComNormal.setText("");
textViewPrecoComPac.setText("");
textViewPrecoComSedex.setText("");
textViewPrecoComTabela.setText("");
linearLayoutPrecoComSedex.setVisibility(View.GONE);
linearLayoutPrecoComPac.setVisibility(View.GONE);
linearLayoutPrecoComExpresso.setVisibility(View.GONE);
linearLayoutPrecoComNormal.setVisibility(View.GONE);
}
// Return the whole list item layout (containing 2 TextViews and an ImageView)
// so that it can be shown in the ListView
return listItemView;
}
效率低下,但它们提供的只是一切。
如果您想要危险地生活,您可以搞乱实施细节,例如手动删除文件和文件夹或使用私有while queue:
queue.pop()
方法执行某些操作。这将是棘手和脆弱的,所以我不推荐它。