#
http://blog.daum.net/haha25/5387585 에서 퍼왔습니다.
private Cursor mTbNoteCursor;
private NoteCursorAdapter mAdapter;
private ListView mListView;
private boolean mReady;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mListView = getListView();
mListView.setTextFilterEnabled(true);
mListView.setOnScrollListener(this);
mIbtnSearch = (ImageButton) findViewById(R.id.ibtnSearch);
mEtSearchTxt = (EditText) findViewById(R.id.etSearchTxt);
mTvHeaderTitle = (TextView) findViewById(R.id.tvHeaderTitle);
mIbtnSearch.setOnClickListener(this);
mGroupListDAO = new GroupListDAO(getApplicationContext());
}
@Override
protected void onResume()
{
super.onResume();
mReady = true;
}
@Override
protected void onPause()
{
super.onPause();
mReady = false;
}
@Override
protected void onDestroy()
{
super.onDestroy();
mReady = false;
try
{
if (mTbNoteCursor != null)
mTbNoteCursor.close();
mGroupListDAO.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
try
{
if (mReady)
{
mTbNoteCursor.moveToPosition(firstVisibleItem);
String firstString = mTbNoteCursor.getString(mTbNoteCursor.getColumnIndex(TbNote.DATE));
mTvHeaderTitle.setText(firstString);
}
}
catch (Exception e)
{}
}
public void onScrollStateChanged(AbsListView view, int scrollState)
{}
// 버튼의 OnClick 이벤트 처리
@Override
public void onClick(View v)
{
switch(v.getId())
{
case R.id.ibtnSearch: // Search Button
findNoteList();
break;
default:
break;
}
}
private void findNoteList()
{
String searchTxt = mEtSearchTxt.getText().toString();
mTbNoteCursor = mGroupListDAO.selectNoteList(searchTxt);
if (mTbNoteCursor != null)
Log.v("GroupList", "mTbNoteCursor.count >>>>>>>>>>>>>>>" + mTbNoteCursor.getCount());
mAdapter = new NoteCursorAdapter(this, R.layout.note_list_item_w_header, mTbNoteCursor, new String[] {TbNote.NOTE}, null);
setListAdapter(mAdapter);
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(200);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
mListView.setLayoutAnimation(controller);
}
}
*******************************************************************
소스 코드는 위와 같고 이를 실행시키면 다음처럼 실행됩니다.
이제 스크롤을 해보면 최상단 그룹명(붉은색 박스)은 고정된 상태로
스크롤 되면서 고정된 헤더의 내용은 현재 데이터의 그룹명으로 계속
변경될 것입니다.
이상으로 GroupList를 개선해 보았습니다.
댓글