我只需要一種方法來顯示默認圖片在所有用於列表視圖的圖像(見下文)。在適配器中使用的ImageView中的默認圖像
此佈局由適配器使用,因此在此佈局上不調用setContentView函數。我認爲這是造成問題的原因(默認圖像沒有出現)。我該如何解決它?
image defaultpic.png位於drawable文件夾中,爲100x100px。
我的代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
tools:context=".MainActivity"
android:background="#222222"
android:paddingTop="2dp"
android:paddingBottom="2dp">
<TextView
android:id="@+id/profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title"
android:textColor="#fcdb8c"
android:background="#222222"
android:textStyle="normal"
android:textSize="15sp"
android:layout_alignParentTop="true"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:paddingRight="40dp"
android:paddingLeft="2dp" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/profile"
android:scaleType = "fitXY"
android:src="@drawable/defaultpic"
android:background="#151515"
android:padding="1dp" />
</RelativeLayout>
@Override
public View getView(View convertView, ViewGroup parent) {
RelativeLayout profileLay = (RelativeLayout)profileInf.inflate
(R.layout.profile_layout, parent, false);
TextView profileView = (TextView)profileLay.findViewById(R.id.profile_name);
ImageView coverView = (ImageView)profileLay.findViewById(R.id.profile);
profileView.setText(currProfile.getName());
Drawable img = Drawable.createFromPath(currProfile.getCover());
coverView.setImageDrawable(img);
return profileLay;
}
*我認爲這是造成這個問題的原因。我該如何解決它?*繼承其中一個可用的適配器。 [這個問題](http://stackoverflow.com/questions/16338281/custom-adapter-getview-method-is-not-called/16338380#16338380)有一個完整的例子 – Blackbelt
粘貼getView代碼並附上listview的圖像 –
@SaurabhKhare粘貼在哪裏? – xRobot