Adapterに他のlayoutをネストxml

3204 ワード

public class OpenDialogAdapter extends ArrayAdapter<Phone> {

	private int resourceId;

	public OpenDialogAdapter(Context context, int textViewResourceId,
			List<Phone> objects) {
		super(context, textViewResourceId, objects);
		resourceId = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
	// 
		/*LayoutInflater mInflater = (LayoutInflater) getContext()
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);*/	
// 
		LayoutInflater mInflater = LayoutInflater.from(getContext());
// layout
		convertView = mInflater.inflate(R.layout.custom_dialog_listview_item,
				null);
		Phone phone = getItem(position);
		TextView typeText = (TextView) convertView.findViewById(R.id.type_view);
		TextView numberText = (TextView) convertView.findViewById(R.id.tv);

		String type = phone.getType();
		typeText.setText(type);
		String number = phone.getNumber();
		numberText.setText(number);
		return convertView;
	}

}

 
メインレイアウト:
//customer_dialog_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
   <ListView
        android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:fillViewport="true">
    </ListView>

 
サブレイアウトcustomer_dialog_listview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    >
    
    
    <TextView 
        android:id="@+id/type_view"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        
        />

        <TextView  
        android:id="@+id/tv"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:textStyle="bold"
        android:gravity="center_vertical"
        />

        
</LinearLayout>

 
onCreat()で
OpenDialogAdapter openDialogAdp = new OpenDialogAdapter(
				ContactActivity.this, R.layout.custom_dialog_listview, extracts);