TYPE TWO CELLS
getView. , , . , , .
. / .
CustomAdapter
private final class CustomArrayAdapter extends ArrayAdapter<String> {
private LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
public CustomArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
super(context, resource, textViewResourceId, objects);
}
...
@Override
public int getItemViewType(int position) {
if () {
return TYPE_1;
} else {
return TYPE_2;
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_1:
convertView = mInflater.inflate(R.layout.row_of_type_1, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.textview_type_1);
break;
case TYPE_2:
convertView = mInflater.inflate(R.layout.row_of_type_2, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.textview_type_2);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getMyCustomTextForThisCell());
return convertView;
}
}
static class ViewHolder {
TextView text;
}
, , , CustomAdapter
private final class CustomArrayAdapter extends ArrayAdapter<String> {
private LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
public CustomArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
super(context, resource, textViewResourceId, objects);
}
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.row_type, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.textview_in_your_row);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getMyCustomTextForThisCell());
return convertView;
}
}
static class ViewHolder {
TextView text;
}
CELL LAYOUT
, , row_type.xml( ) :
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview_in_your_row"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content",
, , - recycle , , EditText
EditText, Android ListView,