Question as follows:
First click, animation right. However, second click, the two white item are moved. Looks like the last movie and broadcast it again, seeking solutions.
Rewrite baseAdapter, class MusicListAdapter extends BaseAdapter.
getView below, set only the selected font and font unselected static effect.
class MusicListAdapter extends BaseAdapter {
Override
public int getCount () {
return list.size ();
}
Override
public Object getItem (int arg0) {
return list.get (arg0);
}
Override
public long getItemId (int arg0) {
return arg0;
}
Override
public View getView (int arg0, View arg1, ViewGroup arg2) {
if (arg1 == null) {
arg1 = getLayoutInflater (). inflate (R.layout.list_item,
null);
}
TextView tv_music_name = (TextView) arg1
.findViewById (R.id.textView1_music_name);
tv_music_name.setTextColor (Color.WHITE);
tv_music_name.setText (list.get (arg0) .substring (18) .replace ("mp3.", "") .replace ("_", "-"));
if (arg0 == FIXMUSICINDEX) {// FIXMUSICINDEX fixed position is selected
tv_music_name.setAlpha (1);
tv_music_name.setTextColor (Color.rgb (30,144,255));
tv_music_name.setTextSize (25);
tv_music_name.setBackgroundResource (R.drawable.colorchange);
tv_music_name.setFocusable (true); // achieve focus in the list
tv_music_name.requestFocus ();
}
else if (arg0 & gt; = 0 & amp; & amp; arg0 & lt; getCount ()) {
tv_music_name.setTextColor (Color.argb (150,255,255,255));
tv_music_name.setShadowLayer (3F, 1F, 1F, Color.argb (255, 200, 200, 200));
tv_music_name.setTextSize (19);
tv_music_name.setBackgroundResource (R.drawable.black);
tv_music_name.getBackground () setAlpha (0);.
}
if (arg0 == getCount ())
clickflag = 0;
return arg1;
} listView Click below to listen to events, write in oncreate (), in the definition of a click here Animations:
listView.setOnItemClickListener (new OnItemClickListener () {
Override
public void onItemClick (AdapterView & lt;? & gt; arg0, View arg1, int arg2,
long arg3) {
orienIndex = arg2-FIXMUSICINDEX;
updatemusiclist ();
if (orienIndex & gt; 0)
arg0.startAnimation (textup);
else if (orienIndex & lt; 0)
arg0.startAnimation (textdown);
clickflag = 1;
listView.clearAnimation ();
listView.getChildAt (currIndex) .startAnimation (tbig);
if (clickflag == 1) {
listView.getChildAt (recordpreviousindex) .startAnimation (tsmall);
}
}
}); Recordpreviousindex position where recording last item 4 of the current position.
This listener when performed several times each click, ah, God horse in one click when there are so many movies?
Reply:
onclick only once you click on the items which passed the appropriate parameters, the first paragraph of the program did not see anything wrong, and the second procedure a bit chaotic
clickflag = 1;
listView.clearAnimation ();
listView.getChildAt (currIndex) .startAnimation (tbig);
if (clickflag == 1) {
listView.getChildAt (recordpreviousindex) .startAnimation (tsmall);
}
Code quality like bad
Anyway, look at the code you must have twice startAnimation, then according to your own needs a good tidy logic
Reply:
Already get. In listView.getChildAt (recordpreviousindex) .startAnimation (tsmall); preceded by a for loop clear each item animation. clickflag is logical confusion product = =
onclick The updatemusiclist () is that, under like to ask you notifyDataSetInvalidated () refresh step, debug like to start executing the start again refreshed.
Because this function is called when clicked, press the keyboard arrow keys are also called, but different refresh order, the first refresh when clicked then the animation, and the keyboard is the first movie and then refresh. . . Solving
public void updatemusiclist () {
temp.clear ();
temp.addAll (list);
list.clear ();
for (int i = 0; i & lt; temp.size (); i ++) {
tempe = i + orienIndex;
if (tempe & gt; = list.size ()) {
tempe = tempe% temp.size ();
}
else if (tempe & lt; 0) {
tempe = temp.size () + tempe;
}
if (tempe == FIXMUSICINDEX)
recordpreviousindex = i;
if (tempe & lt; temp.size ())
list.add (temp.get (tempe));
} // End for
currIndex = FIXMUSICINDEX;
listView.requestFocus ();
listView.setSelection (FIXMUSICINDEX);
// ***************************************
ma.notifyDataSetInvalidated ();
// ***************************************
start ();
} Reply:
http://blog.csdn.net/bailyzheng/article/details/8536806
General situation is notifyDataSetChanged, I do not know if you belong to the data source fails or changes, please refer to the above link!
Keyboard should be directly departure refresh before heading inside getView animation, but your onclick also manually refresh the departure should be the same,
However onclick you manually to trigger another animation, this may have an impact.
In fact, no need to be so complicated, simplify logic about it
Reply:
Here it is to achieve a keyboard and mouse control modes
Every mouse click or keyboard press the whole data source changes
Reply:
The landlord, seeking the source, ah, I would like to put forward such animation, but do not know ah
No comments:
Post a Comment