Here is a simple test case that does the same thing.
I am trying to get the yellow background to stretch the entire row (I
can do this by changing my design, but I need/want the list inside a
linear layout, and I need each view of the list to be a table).
If you run this you will get a ClassCast
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
ListView list = new ListView(this);
list.setBackgroundColor(Color.GREEN);
list.setAdapter(new TestAdaptor(new String[] { "kronenburg",
"san
miguel", "sam adams" }));
layout.addView(list);
setContentView(layout);
}
}
class TestAdaptor extends BaseAdapter {
private final String[] strings;
public TestAdaptor(String[] strings) {
this.strings = strings;
}
public int getCount() {
return strings.length;
}
public Object getItem(int position) {
return strings[position];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
TableLayout table = new TableLayout(parent.getContext());
table.setBackgroundColor(Color.RED);
table.setLayoutParams(new
TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
TableRow row = new TableRow(parent.getContext());
row.setBackgroundColor(Color.YELLOW);
table.addView(row);
TextView textView = new TextView(parent.getContext());
textView.setText((String) getItem(position));
row.addView(textView);
return table;
}
}
On Jul 5, 12:32 pm, Mark Murphy <[email protected]> wrote:
> On Mon, Jul 5, 2010 at 1:23 PM, samspade79 <[email protected]> wrote:
> > Not sure what you mean by what class it really is? I'm instantiating
> > it directly in code so I know what class it is (or at least I think I
> > do?)
>
> Whoops, sorry, misread your post. I thought the ClassCastException was
> on retrieving the existing LayoutParams, not setting them. You could,
> however, examine what the existing LayoutParams are, using your
> debugger or Log.
>
> How are you creating your rows? If you are inflating them from layout
> XML files, be sure to use the inflate(R.layout.whatever, parent, true)
> call.
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Consulting:http://commonsware.com/consulting
--
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en