我必須在列表視圖上執行一次點擊,在onItemClick我得到所選視圖的位圖。當我手動點擊它的工作,但是當我以編程方式進行點擊,視圖的高度等於我的代碼0 這裏片段PerformClick在ListView上返回一個高度等於0的視圖(Android)
listMedic.performItemClick(
getViewByPosition(position), position, adapter.getItemId(position));
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
ListElement elem = (ListElement) listMedic.getItemAtPosition(position);
try {
QuantityPopUp quantityPopUp = new QuantityPopUp(context);
quantityPopUp.setImageAndPosition(getBitMapOfView(v), v, this, getResources().getString(R.string.valid_q_text_bt));
quantityPopUp.setQuantity(Float.parseFloat(elem.getqDonn().replace(',', '.')));
quantityPopUp.setListElementAdapter((ListElementAdapter) listMedic.getAdapter());
quantityPopUp.setIndex(position);
contentLayout.addView(quantityPopUp);
popUpI = quantityPopUp;
darkenView();
} catch (NullPointerException e) {
}
}
private Bitmap getBitMapOfView(View v){
//récupérer la vue en tant que bitmap
v.setDrawingCacheEnabled(true);
v.buildDrawingCache();
return Bitmap.createBitmap(v.getDrawingCache(true));
}
public View getViewByPosition(int pos) {
final int firstListItemPosition = listMedic.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listMedic.getChildCount() - 1;
if (pos < firstListItemPosition || pos > lastListItemPosition) {
return listMedic.getAdapter().getView(pos, null, listMedic);
} else {
final int childIndex = pos - firstListItemPosition;
return listMedic.getChildAt(childIndex);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_element_layout, parent, false);
}
// récupérer l'item par sa position dans la vue
ListElement listElement = getItem(position);
//récupérer les éléments à remplir
LinearLayout listElementLayout = (LinearLayout) convertView.findViewById(R.id.listElementLayout);
TextView denomMedic = (TextView) convertView.findViewById(R.id.denomMedic);
TextView denom2Medic = (TextView) convertView.findViewById(R.id.denom2Medic);
TextView qPres = (TextView) convertView.findViewById(R.id.qPres);
TextView qDonn = (TextView) convertView.findViewById(R.id.qDonn);
ImageView compIcon = (ImageView) convertView.findViewById(R.id.compIcon);
//définir un touch listener pour afficher l'historique
listElementLayout.setTag(position);
//remplir les elements avec les informations
denomMedic.setText(listElement.getDenomMedic());
denom2Medic.setText(listElement.getDenom2Medic());
qPres.setText(listElement.getqPres());
qDonn.setText(listElement.getqDonn());
compIcon.setImageDrawable(listElement.getIconBac());
//retourner l'élément construit
return convertView;
}
getViewByPosition()如何工作? –
哦,對不起,我錯過了 –
請添加getViewByPosition()代碼作爲您的問題的一部分(這是很難閱讀裏面的評論)。你還可以添加你的getView()代碼嗎? –