我正在尝试将一个小的主图标图像添加到列表视图的顶部。您可以看到我的适配器的代码。它非常适合设置动态文本,但是当我想添加图像时它会失败。
我没有遇到任何运行时错误,只是未加载图像。
引用的图像是35x35 png文件。
如何实现?我刚接触到android。请指导我。
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); viewList = Nexttopic.this.getLayoutInflater().inflate(R.layout.activity_nexttopic, null); dialogMarketList = new Dialog(Nexttopic.this); dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE); dialogMarketList.setContentView(viewList); dialogMarketList.show(); lvForDialog = (ListView) viewList.findViewById(R.id.List_view); lvForDialog.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); ArrayAdapter<String> adapter = (new ArrayAdapter<String>(Nexttopic.this, R.layout.row_topic, R.id.child_row,tnamelist)); ImageView home = (ImageView) findViewById(R.id.hme); lvForDialog.setAdapter(adapter);
row_topic xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<ImageView android:id="@+id/hme"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@+id/child_row"
android:src="@drawable/homex"/>
<TextView
android:id="@+id/child_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="@drawable/bg"/>
</RelativeLayout>
activity_nexttopic
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Nexttopic" >
<ListView
android1:id="@+id/List_view"
android1:layout_width="match_parent"
android1:layout_height="250dp"
android1:layout_centerHorizontal="true"
android1:layout_centerVertical="true"
android:background="@drawable/bg">
</ListView>
</RelativeLayout>