我的listview项目有文本视图,图像视图和复选框。当我点击复选框我得到setonclick监听器的事件时,我需要删除带动画的已删除行。
所以,对于这个,如果我使用复选框视图,我只获得动画外观的复选框,而不是其他视图,如textview,imageview。
这是动画代码
OnClickListener CheckboxListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CheckBox cb = (CheckBox) v ;
final Animation animation = AnimationUtils.loadAnimation(v.getContext(), R.anim.splashfadeout);
v.startAnimation(animation);
Handler handle = new Handler();
handle.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mcompletecallback.completePressedItem(cursorHelper.primaryKey);
notifyDataSetChanged();
animation.cancel();
}
}, 1000);
}
}
在这个v
是复选框视图,但我想知道隐藏的视图复选框,如果我在其上应用动画,它可以顺利运行。但我想知道如何在这里得到它?
这是我的动画xml代码
<?xml version="1.0" encoding="utf-8"?>
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
我的适配器代码
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String todayDate = Utilities.getTodayDate();
String tomorrowDate = Utilities.getTomorrowDate();
ViewHelper viewholder = null;
DividerHelper dividerviewholder = null;
int view = getItemViewType(position);
if(view == TYPE_HEADER)
{
//perform header actions
}
else
{
//Cursor c = (Cursor) getItem(position-cursorPosition);
Cursor c = (Cursor) getItem(position);
if(convertView == null)
{
viewholder = new ViewHelper();
convertView = mLayoutInflater.inflate(R.layout.layout_item, parent, false);
viewholder.title = (TextView)convertView.findViewById(R.id.ID_item_title);
viewholder.Notes = (TextView)convertView.findViewById(R.id.ID_item_notes);
viewholder.Status = (CheckBox)convertView.findViewById(R.id.ID_item_is_completed_checkbox);
convertView.setTag(viewholder);
viewholder.Status.setTag(viewholder);
viewholder.Status.setOnClickListener(completedCheckboxListener);
}
else
{
viewholder = (ViewHelper)convertView.getTag();
}
viewholder.primaryKey = c.getInt(0);
viewholder.Notes = c.getString(9);
viewholder.Title = c.getString(3);
}
return convertView;
}
答案 0 :(得分:1)
在该列表视图上应用onItemClickListener,当您单击该行时,您将获得
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
//here "view" is your complete row that you clicked where you can find your checkbox
}
答案 1 :(得分:0)
感谢Sripathi & Navjot Bedi
我能够弄明白该怎么做,
我们需要调用View v1 = (View) cb.getParent();
来获取复选框的父视图,然后
在V1对象上调用动画,
动画动画= AnimationUtils.loadAnimation(v1.getContext(),R.anim.splashfadeout); CompleteUponCompletionofAnimation(animation,cursorHelper.key); v1.startAnimation(动画);
public void CompleteUponCompletionofAnimation(Animation fadeout, final int pk)
{
fadeout.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
//your change at end of animation
notifyDataSetChanged();
}
});
}
同样在convertview中,通过设置NULL
来删除动画if(convertView == null)
{
}
else
{
if(convertView.getAnimation() != null)
convertView.setAnimation(null);
}