getView()
リストビュー アダプタでメソッドをオーバーライドする必要があります。各アイテムのレイアウトを表示する責任があります。そこで次のようなことができます:
if(position == YOUR_MOVE_POSITION) {
// here hide ordinary elements, and set the ones you need to be visible
}
詳細については、こちらをご覧ください:リンク
例: (解決策の見方)
このメソッドはアダプタ クラスにあります ( ListView
.
public View getView(int position, View convertView, ViewGroup parent) {
final View v;
if(position == 1) { // here come instructions for 'header' no.1
v = createViewFromResource(position, convertView, parent, mResource);
// the widget you want to show in header:
ImageView yourMoveImage = (ImageView) v.findViewById(R.id.your_move);
// and here come widgets you don't want to show in headers:
ImageView otherWidget = (ImageView) v.findViewById(R.id.other_widget);
// then you set the visibility:
yourMoveImage.setVisibility(View.VISIBLE); // here is the key
otherWidget.setVisibility(View.GONE); // it may also be View.INVISIBLE (look up the official docs for details)
} else {
if(position == 5){ // here come instructions for 'header' no.1
v = createViewFromResource(position, convertView, parent, mResource);
// the widget you want to show in header:
ImageView theirMoveImage = (ImageView) v.findViewById(R.id.their_move);
// and here come widgets you don't want to show in headers:
ImageView otherWidget = (ImageView) v.findViewById(R.id.other_widget);
// then you set the visibility:
yourMoveImage.setVisibility(View.VISIBLE); // here is the key
otherWidget.setVisibility(View.GONE); // it may also be View.INVISIBLE (look up the official docs for details)
} else {
// if it is the regular item, just show it as desribed in your XML:
v = createViewFromResource(position, convertView, parent, mResource);
}
}
return v;
}