여기서 많은 도움 받고 있습니다. 정말 감사드려요^^
이 코드 대강적으로 해석 좀 부탁드려도 될까요?
혼자보면서 해봤는데 좀 어설프고 해서 도움 좀 받고 싶어서요
부탁드리겠습니다^^
package adapter;
import test.android.study.R;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyTIArrayAdapter extends ArrayAdapter< String > {
private Context mcontext;
private String[] strarray = null;
private int drawable = 0;
public MyTIArrayAdapter( Context _context, String[] _strar, int _drawab ) {
super( _context, R.layout.layout_view_ti, _strar );
/* get context */
mcontext = _context;
// TODO Auto-generated constructor stub
drawable = _drawab;
strarray = _strar;
}
@Override
public View getView( int _position, View _convertView, ViewGroup _parent ) {
Log.d( "debug", "_position : " + _position );
if( _convertView == null ) {
// Log.d( "debug", "_convertView is null!" );
LayoutInflater vi = ( LayoutInflater ) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
_convertView = vi.inflate( R.layout.layout_view_ti, null );
// String data = strarray[ _position ];
String _data = this.getItem( _position ).toString();
TextView name = ( TextView ) _convertView.findViewById( R.id.ti_item_text );
ImageView btn = ( ImageView ) _convertView.findViewById( R.id.ti_item_img );
btn.setBackgroundResource( R.drawable.arrow );
//
name.setText( _data );
name.setTextColor( Color.DKGRAY );
}
else {
// TextView name = ( TextView ) _convertView.findViewById( R.id.ti_item_text );
// String data = strarray[ _position ];
// Log.d( "debug", "not null data : " + data );
// name.setText( data );
// name.setTextColor( Color.DKGRAY );
}
return _convertView;
}
}
음 전체적으로 설명을 해 달라고 하면.... 많은 내용이 필요할 것이고요.
위 소스는 Custom ListView로써 getView 함수는 ListView의 한줄,한줄에 대한 성능을 향상시키기 위해 재정의되어지는 함수입니다.
_convertView == null은 맨 위 한줄에 대한 Layout을 정의하는 곳입니다. 보통은 임의로 만든 xml를 추가해 줍니다.
if 문 내에서 맨 아래에 _convertView.setTag(...) 해 주고요,
....
else
{
aHolder = (XXXXXXHolder)convertView.getTag();
}
통해서 aHolder 를 받고 아래부분에서 여러 기능을 추가하면 됩니다.