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/a ... -with.html
I have a class that extends ListActivity and looks like this:
Using java Syntax Highlighting
- 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();
- }
- }
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
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:
Using java Syntax Highlighting
- 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;
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
And DDListRow, which extends LinearLayout looks like this:
Using java Syntax Highlighting
- 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);
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
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

