Hi,
I'm trying to reproduce the contact list component (I can't find it to
inlude it in my app). So I did a compound view like this for each
phone item: phone_list_item.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:id="@+id/phone_list_item_button_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/phone_list_item_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton android:src="@android:drawable/ic_delete"
android:id="@+id/phone_list_item_button_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
with a corresponding initialisation
public class PhoneListItem extends LinearLayout {
protected Resources resources;
protected Button type;
protected EditText value;
protected ImageButton removeButton;
protected Phone phone;
public PhoneListItem(Context context) {
super(context);
resources = getResources();
LayoutInflater inflater = (LayoutInflater) getContext
().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.phone_list_item, this, true);
type = (Button) findViewById(R.id.phone_list_item_button_type);
value = (EditText) findViewById(R.id.phone_list_item_value);
removeButton = (ImageButton) findViewById
(R.id.phone_list_item_button_remove);
removeButton.setImageResource(android.R.drawable.btn_minus);
}
public PhoneListItem(Context context, Phone phone) {
this(context);
setPhone(phone);
}
public Phone getPhone() {
phone.setNumber(value.getText().toString());
return phone;
}
public void setPhone(Phone phone) {
this.phone = phone;
type.setText(resources.getString(phone.getType()));
value.setText(phone.getNumber());
}
}
then a parent compound view to handle the list: phone_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/phone_list_main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout android:id="@+id/phone_list_cmds"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="@string/phone_list_label"
android:id="@+id/
phone_list_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<ImageButton android:id="@+id/phone_list_button_add"
android:src="@android:drawable/btn_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="right"></
ImageButton>
</LinearLayout>
<TableLayout android:id="@+id/phone_list_items"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableLayout>
</LinearLayout>
with its class:
public class PhoneListView extends LinearLayout {
protected TableLayout phoneListTable;
protected ImageButton addPhoneButton;
protected ArrayAdapter<Phone> adapter;
protected ArrayList<Phone> phones = new ArrayList<Phone>();
public PhoneListView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
LayoutInflater inflater = (LayoutInflater) getContext
().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.phone_list, this, true);
phoneListTable = (TableLayout)
findViewById(R.id.phone_list_items);
addPhoneButton = (ImageButton) findViewById
(R.id.phone_list_button_add);
// addPhoneButton.setImageResource(android.R.drawable.btn_plus);
}
public ArrayList<Phone> getPhones() {
return phones;
}
public void setPhones(ArrayList<Phone> phones) {
this.phones = phones;
phoneListTable.removeAllViews();
for (Phone phone : phones) {
Context context = getContext();
TableRow row = new TableRow(context);
row.addView(new PhoneListItem(context, phone));
// EditText editText = new EditText(context);
// editText.setText(phone.getNumber());
// row.addView(editText);
phoneListTable.addView(row);
}
phoneListTable.postInvalidate();
}
}
When I attempt to display it, it displays for a while then I have the
following exception:
I just included the view to a linear layout:
<eu.nextstreet.android.compound.PhoneListView android:id="@+id/
view_entity_phones" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
and add it phones like this:
blcPhones = (PhoneListView)
findViewById(R.id.view_entity_phones);
blcPhones.setPhones(geoLocationFlag.getPhones());
As I said the page displays correctly then throws this exception. Any
one has an idea?
Best Regards,
Zied Hamdi
07-17 18:42:41.107: ERROR/AndroidRuntime(1054):
java.lang.StackOverflowError
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.graphics.Canvas.drawText(Canvas.java:1217)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.text.SpannableStringBuilder.drawText
(SpannableStringBuilder.java:1045)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.graphics.Canvas.drawText(Canvas.java:1273)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.text.Styled.each(Styled.java:119)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.text.Styled.foreach(Styled.java:249)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.text.Styled.drawText(Styled.java:302)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.text.Layout.drawText(Layout.java:1346)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.text.Layout.draw(Layout.java:339)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.widget.TextView.onDraw(TextView.java:3921)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.View.draw(View.java:5838)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.View.draw(View.java:5944)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.widget.FrameLayout.draw(FrameLayout.java:352)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.View.draw(View.java:5841)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.widget.FrameLayout.draw(FrameLayout.java:352)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1486)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.drawChild(ViewGroup.java:1484)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.View.draw(View.java:5841)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.widget.FrameLayout.draw(FrameLayout.java:352)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
com.android.internal.policy.impl.PhoneWindow$DecorView.draw
(PhoneWindow.java:1847)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewRoot.draw(ViewRoot.java:1217)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.os.Looper.loop(Looper.java:123)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
android.app.ActivityThread.main(ActivityThread.java:3948)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
java.lang.reflect.Method.invokeNative(Native Method)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
java.lang.reflect.Method.invoke(Method.java:521)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-17 18:42:41.107: ERROR/AndroidRuntime(1054): at
dalvik.system.NativeStart.main(Native Method)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---