[英]Android ImageView won't load on CustomList with ViewHolder
I have a custom list view which I recently upgraded to use View Holder. 我有一个自定义列表视图,最近将其升级为使用View Holder。 Right now the project works fine but the images in the two Image Views don't show on the screen.
现在,该项目可以正常工作,但两个“图像视图”中的图像不会显示在屏幕上。
This two black icons appear "transparent" but work if I click them. 这两个黑色图标显示为“透明”,但如果单击它们,它们将起作用。
This is the layout: 这是布局:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgInfo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"
android:layout_weight="0.04"
android:visibility="visible"
app:srcCompat="@drawable/details64" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imgInfo"
android:layout_toLeftOf="@+id/imgEdit"
android:layout_toRightOf="@+id/imgInfo"
android:layout_weight="0.24"
android:orientation="vertical">
<TextView
android:id="@+id/txtChamado"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="25sp" />
<TextView
android:id="@+id/txtSolicitante"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="15sp" />
<TextView
android:id="@+id/txtItemDeCatalogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="15sp" />
</LinearLayout>
<ImageView
android:id="@+id/imgEdit"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="12dp"
android:layout_weight="0.03"
android:contentDescription=""
app:srcCompat="@drawable/pencil64" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
This is the code snippet: 这是代码片段:
@Override
public View getView(final int position, View view, final ViewGroup parent) {
View convertView;
ViewHolder holder;
if (view == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.customized_list_view, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}else{
convertView = view;
holder = (ViewHolder) convertView.getTag();
}
// Object declaration
final Sette setteData = getItem(position);
//region Put the Tasks values to the textviews
// Get me two strings, one with the older value and one with the newest
String oldChamado = holder.txtChamado.getText().toString();
String newChamado = setteData.getChamado();
// Do not repeat the string in the textview
if (!(oldChamado.equals(newChamado))) {
holder.txtChamado.setText(newChamado);
}
//region Click Listener for the button that leads to Approvals Activity
if (!aBoolean) {
holder.imgEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
chamadoClicked = setteData.getChamado();
solicitanteClicked = setteData.getSolicitante();
itemDeCatalogoClicked = setteData.getItemDeCatalogo();
id = setteData.getId();
Intent intent = new Intent(context.getApplicationContext(), ApprovalsActivity.class);
intent.putExtra("Id", id);
intent.putExtra("chamadoClicked", chamadoClicked);
intent.putExtra("solicitanteClicked", solicitanteClicked);
intent.putExtra("itemDeCatalogoClicked", itemDeCatalogoClicked);
context.startActivity(intent);
}
});
}
//endregion
return convertView;
}// END METHOD
ViewHolder (which I got from an internet example): ViewHolder(我从一个互联网示例中获得):
public class ViewHolder {
TextView txtChamado;
TextView txtSolicitante;
TextView txtItemDeCatalogo;
ImageView imgInfo, imgEdit;
Typeface bebasKai;
Typeface london;
public ViewHolder(View view){
bebasKai = Typeface.createFromAsset(context.getAssets(), "fonts/bebaskai.otf");
london = Typeface.createFromAsset(context.getAssets(), "fonts/london.ttf");
txtChamado = (TextView) view.findViewById(R.id.txtChamado);
txtChamado.setTypeface(bebasKai);
txtSolicitante = (TextView) view.findViewById(R.id.txtSolicitante);
txtSolicitante.setTypeface(london);
txtItemDeCatalogo = (TextView) view.findViewById(R.id.txtItemDeCatalogo);
txtItemDeCatalogo.setTypeface(london);
imgEdit = (ImageView) view.findViewById(R.id.imgEdit);
imgInfo = (ImageView) view.findViewById(R.id.imgInfo);
}
}
I tried clean, rebuild, download the project from BitBucket again, reinstall the app from scratch on my phone, invalidade cache/restart and check the code. 我尝试清理,重建,再次从BitBucket下载项目,从头开始在手机上重新安装应用程序,使缓存无效/重新启动并检查代码。
Am I missing something obvious here? 我在这里错过明显的东西吗?
**EDIT:**Thank you SaNtoRiaN, I knew it was something simple that I was missing. **编辑:**谢谢您,我知道我很想念这件事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.