1 package com.google.android.test.shared_library; 2 3 import android.content.Context; 4 import android.content.res.TypedArray; 5 import android.util.AttributeSet; 6 import android.view.LayoutInflater; 7 import android.view.View; 8 import android.widget.LinearLayout; 9 import android.widget.TextView; 10 11 public class AddressView extends LinearLayout { 12 private TextView mNameView; 13 private TextView mStreetView; 14 private TextView mCityStateZipView; 15 private TextView mCountryView; 16 AddressView(Context context, AttributeSet attrs)17 public AddressView(Context context, AttributeSet attrs) { 18 super(context, attrs); 19 setOrientation(VERTICAL); 20 21 View view = LayoutInflater.from(context).inflate(R.layout.address, this); 22 mNameView = (TextView) view.findViewById(R.id.name); 23 mStreetView = (TextView) view.findViewById(R.id.street); 24 mCityStateZipView = (TextView) view.findViewById(R.id.cityStateZip); 25 mCountryView = (TextView) view.findViewById(R.id.country); 26 27 TypedArray a = context.getTheme().obtainStyledAttributes( 28 attrs, 29 R.styleable.AddressView, 30 0, 0); 31 try { 32 mNameView.setText(a.getString(R.styleable.AddressView_name)); 33 int streetNumber = a.getInteger(R.styleable.AddressView_streetNumber, -1); 34 mStreetView.setText((streetNumber <= 0 ? "" : Integer.toString(streetNumber)) + 35 " " + a.getString(R.styleable.AddressView_streetName)); 36 mCityStateZipView.setText(a.getString(R.styleable.AddressView_city) + ", " + 37 a.getString(R.styleable.AddressView_state) + " " + 38 a.getString(R.styleable.AddressView_zip)); 39 mCountryView.setText(a.getString(R.styleable.AddressView_country)); 40 } finally { 41 a.recycle(); 42 } 43 } 44 } 45