我想为listView项目创建动画,例如旋转或移动。现在在我的数组适配器我想触摸项目后我可以设置动画。在这段代码中,我有数组适配器,但我无法在setAnimationListener
方法中使用fill
。
总结了 MainActivity:
public class ActivityMainView extends SlidingFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main_view_container);
/* SAVE current context */
G.context = getBaseContext();
mSlidingMenu = getSlidingMenu();
mSlidingMenu.setShadowDrawable(R.drawable.shape_sliding_menu_shadow);
mSlidingMenu.setShadowWidthRes(R.dimen.sliding_menu_shadow_width);
mSlidingMenu.setBehindOffsetRes(R.dimen.sliding_menu_offset);
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
mSlidingMenu.setMode(SlidingMenu.RIGHT);
mSlidingMenu.setFadeDegree(0.15f);
UiFiller uiFiller = new UiFiller(mSlidingMenu);
uiFiller.laySlideMenuSmsReceive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showSelectedItem(M.MIS_ReciveSMS);
}
});
private void showSelectedItem(int index) {
Fragment mFragment = null;
if (index == mLastMenuItemSelected)
return;
FragmentTransaction fts = getSupportFragmentManager().beginTransaction();
if (mLastViewFragment != null) {
fts.remove(mLastViewFragment);
}
switch (index) {
case M.MIS_ReciveSMS:
mFragment = new FragmentSmsReceive();
txtSelectedSlideTitle.setText(UC.getResourcesText(R.string.slide_menu_sms_receive));
break;
}
fts.replace(R.id.smsViewFragment, mFragment);
fts.commit();
mLastMenuItemSelected = index;
mSlidingMenu.showContent(true);
mLastViewFragment = mFragment;
}
}
汇总FragmentSmsReceive()
:
public class FragmentSmsReceive extends Fragment {
private static final Boolean DEBUG = true;
public ArrayAdapter adapter;
private ArrayList<StructReceiveSms> receiveSmsArray;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
G.currentActivity = FragmentSmsReceive.this.getActivity();
adapter = new AdapterReceiveSms(G.smsArray);
}
}
Summarized AdapterReceiveSms ArrayAdapter:
public void fill(final ArrayAdapter<StructReceiveSms> adapter, final StructReceiveSms item, final int position) {
uiFiller.txtSmsReceiveItemContactName.setText(item.mobile);
uiFiller.txtSmsReceiveItemDate.setText(item.mDate);
uiFiller.txtSmsReceiveItemSmsBody.setText(item.smsBody);
animMove = AnimationUtils.loadAnimation(G.currentActivity, R.anim.move);
// set animation listener
Animation.AnimationListener listener = (AnimationListener) G.context;
animMove.setAnimationListener(listener);
uiFiller.layoutRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
uiFiller.layoutRoot.startAnimation(animMove);
}
});
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vHolder;
StructReceiveSms item = getItem(position);
if (convertView == null) {
convertView = G.inflater.inflate(R.layout.activity_sms_receive_item, parent, false);
vHolder = new ViewHolder(convertView);
convertView.setTag(vHolder);
} else {
vHolder = (ViewHolder) convertView.getTag();
}
vHolder.fill(this, item, position);
return convertView;
}
错误:
The method setAnimationListener(Animation.AnimationListener) in the type Animation is not applicable for the arguments
答案 0 :(得分:0)
我假设G.currentActivity
正在引用ListView的父活动。无论您分配给setAnimationListener
的是什么,都需要实施Animation.AnimationListener interface.
确保您的活动正在实施此界面。执行此操作后,可以将适配器中的上下文转换为此接口类,然后将引用分配给接口。像下面这样的东西。注意:这不在我的头顶,未经测试。
Animation.AnimationListener listener = (AnimationListener) context;
animMove.setAnimationListener(listener);