[Mono-bugs] [Bug 645249] Setting LinearLayout.LayoutParams causes a java.lang.ClassCastException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Nov 2 15:43:44 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=645249

https://bugzilla.novell.com/show_bug.cgi?id=645249#c4


Jonathan Pryor <jpryor at novell.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #4 from Jonathan Pryor <jpryor at novell.com> 2010-11-02 19:43:43 UTC ---
For reference, the Java code I used:


package com.jprl.ca;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import java.util.*;

public class JavaCustomAdapter extends Activity {
    int clicks;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button b = (Button) findViewById(com.jprl.ca.R.id.myButton);
        b.setOnClickListener(new OnClickListener () {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                b.setText (clicks++ + " clicks!");
            }

        });

        ListView lstItems = (ListView) findViewById(com.jprl.ca.R.id.lstItems);
        if (lstItems != null) {
            List<Item> items = new ArrayList<Item>();
            items.add(new Item (1, "First Item", "First item description"));
            items.add(new Item (2, "Second Item", "Second item description"));

            ListAdapter adapter = new ListAdapter(this);
            adapter.setData(items);
            lstItems.setAdapter(adapter);
        }
    }
}

class Item {
    public int ID;
    public String Name;
    public String Description;

    public Item (int id, String name, String description)
    {
        ID = id;
        Name = name;
        Description = description;
    }
}

class ListAdapter extends BaseAdapter {
    protected Activity _context;
    List<Item> data;

    public ListAdapter(Activity context)
    {
        _context = context;
    }

    public void setData(List<Item> data)
    {
        this.data = data;
    }

    @Override
    public int getCount()
    {
        return data.size();
    }

    @Override
    public Object getItem(int position)
    {
        return data.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LinearLayout itemRow = new LinearLayout(_context);
        itemRow.setOrientation(LinearLayout.HORIZONTAL);
        itemRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));

        TextView text = new TextView(_context);
        itemRow.addView(text);
        text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
        text.setText(data.get(position).Name);

        return itemRow;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return data.get(position).ID;
    }
}

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list