2

当前我试图让自定义微调工作。它使用自定义布局,并且它的arrayadapter被自定义对象填充。现在我想要一个图标出现在微调器中的每个对象旁边。自定义微调器与动态对象和动态图标

到目前为止,我使用的代码看起来像这样:

// create spinner 
    logicSpinner = (Spinner) view.findViewById(R.id.logicSpinner); 
    logicAdapter = new ArrayAdapter<SearchLogic>(parent, R.layout.icon_spinner_layout, R.id.typesfield, myLogics); 
    logicSpinner.setAdapter(logicAdapter); 

其中myLogics提供类型SearchLogic的ArrayList的。该SearchLogic类看起来像这样

public class SearchLogic { 

    private String otherString; 
    private String localString; 
    private int  imageRes; 

    public SearchLogic(String otherString, String localString, int imageRes){ 
     this.otherString = otherString; 
     this.localString = localString; 
     this.imageRes = imageRes; 

    } 
    /* 
    * let's override the toString method since thats the method a spinner object uses as default value for its entries 
    */ 
    @Override 
    public String toString(){ 
     return this.localString; 
    } 

的icon_spinner_layout看起来是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/ObjectSpecificIcon" 
     android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
     android:src="@drawable/ic_launcher"/> 
    <TextView 
     android:id="@+id/typesfield" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

现在我正在制作新的SearchLogic对象,并将其添加到myLogics像这样:

myLogics.add(new SearchLogic("string1", "string2", R.drawable.iconXYZ)); 

我希望“ObjectSpecificIcon”中填充了传递给SearchLogic对象的图标。怎么做?是否可以在layout.xml文件中提供“占位符”而不是提供硬编码的src?或者其他方式?

+0

得到了一些家伙。找到了一个办法,但仍然没有按照我的意愿工作。我会告诉你什么时候我追捕最后的问题,然后在这里发布代码。 – masi

回答