Hi folks,

I am a complete newbie to android so I guess this group is just the 
right one for me to start with :-)

I have the following problem. I have written my own ArrayAdapter class 
which cutomizes a ListView. More precisely I would like to have a list 
which contains a horizontal LinearLayout with one TextView and a 
ImageView per row. I have tried to achieve this by using the attached 
code which I created by following this tutorial 
http://lbellonda.blogspot.com/2007/12/android-how-to-show-items-with.html

I have a class that extends ListActivity and looks like this:

public class DDboard extends ListActivity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
       
        try{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dd_list);
       
        String[] string1 = new String[2];
        string1[0] = "Description 1";
        string1[1] = "green";
       
        String[] string2 = new String[2];
        string1[0] = ""Description 2";
        string1[1] = "yellow";
       
        String[] string3 = new String[2];
        string1[0] = ""Description 3";
        string1[1] = "red";
       
        ArrayList dAL = new ArrayList();
       
        dAL.add(string1);
        dAL.add(string2);
        dAL.add(string3);
       
        DArrayAdapter daa = new DArrayAdapter(this, dAL);
        setListAdapter(daa);
       
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

Within this class, as you can see, I do instantiate DArrayAdapter and 
sending the current context and my ArrayList. Depending on what is in 
[1] of the String array I would like to place different images in my 
ImageView. But have a look at that later.

DArrayAdapter looks like this:

public class DArrayAdapter extends ArrayAdapter{

    public DArrayAdapter(Context context, List<String[]> dds) {
        super(context, R.layout.dd_row, dds);
    }
   
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        String[] stringArray = (String[]) getItem(position);
        DDListRow ddlr = new DDListRow(super.getContext(), stringArray);
        return ddlr;
    }
}

And DDListRow, which extends LinearLayout looks like this:


public class DemandDashboardListRow extends LinearLayout {

    //String Title="";
    TextView mText;
    ImageView mView;
   
    public DDListRow(Context context, String[] dd) {
        super(context);
       
        this.setOrientation(HORIZONTAL);
        this.setLayoutParams(new 
LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
LayoutParams.WRAP_CONTENT));
       
        mText = new TextView(context);
        mText.setLayoutParams(new 
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT));
        addView(mText);
        setText(dd[0]);
       
        mView = new ImageView(context);
        mView.setLayoutParams(new 
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT));
       
        if (demand[1].equals("red")){
            mView.setImageResource(R.drawable.android_red);
        }
        if (demand[1].equals("yellow")){
            mView.setImageResource(R.drawable.android_yellow);
        }
        if (demand[1].equals("green")){
            mView.setImageResource(R.drawable.android_green);
        }
        addView(mView);
    }
    public void setText(String text)
    {
        mText.setText(text);
    }
}

I hope this is at least not complete BS but if I run the programm I get 
a ClassCastException at the method call "setListAdapter(daa);" in the 
ListActivity class. And to be honest, I don't have a clue what I am 
doing wrong. The res/layout files are created as described in the 
well-known notepad tutorial but I would post them immediately if they 
are of any help for you guys to solve my issue.

Any help is greatly appreciated!!!

Cheers
Peter

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to