I have a list view and two buttons(play & pause) I want that to when a play button touched a list view's first item go on top of page for example for 6 seconds and next item after first item be on top for 3 seconds and ...
This means Successively items go to top of list view's page and when I touch pause button it stop working and when I touch play button again it continue working
What can I do?
Sorry For my poor English
Sorry
you can keep a track of the last visible item on the screen like a counter. On click of play button increase the value of counter by 1 and set smooth scroll to the counter value. Do this inside a Timer object pass a TimerTask to create a new timer object and schedule it to run over and over again. Hope this helps.
http://developer.android.com/reference/java/util/Timer.html
http://developer.android.com/reference/java/util/TimerTask.html
Related
I am developing music application for android. I am done with most of the parts but i need help for Listview .
Suppose that user selects a song from list in Main and then it goes to new activity to play that song. In new activity user has option for next button to play next song . Now when user clicks next button 10 times and consider current playing song is XYZ. when user come back to main activity i want to highlight that song XYZ from list and display it on top of screen from list.
Please advise how to show that song on top in listview. I am able to find the position of XYZ from list but don't know how to highlight it and display it on top in current list.
Hope i made myself clear about this whole.
thanks in advance.
i would suggest that when you enter the new activity of playing the song you save the position of the song in your case XYZ.
so now when you go back use that value and pass it to your intent. and in your main activity u get the value so set the postion of the listview.
lv.smoothScrollToPosition(position);
Hope this helps you
Have you considered adding a header and then is there is a selected song you add that song as the header if there is no selected song you set header visibility to GONE.
You face 2 problems:
Hight light the row at selected song:
You can try set background at the selected song view to hight light it.
Show the playing song at the top of the ListView.
About show to top ListView. You can use ListView.addHeader... to add playing song view to top view.
Hope you solve it
I am trying to set focus on a specific index on list view. I am trying a scenario where I have buttons for up and down when I press the button Up I want to set the focus on upper index of the list view and the same goes for the down button press. I have researched a lot on the internet but I have not been able to find any useful resource. Any suggestions to move the focus between the list view nodes/indexes will be really appreciated.
If there is no any selection on listview for first time you can set selected position as 0, on down button press you can increase position by 1 and decrease by 1 for UP button press.
listview.setSelection(position);
adapter.notifyDataSetChanged();
This will work for you.
I have a listview with play button to play songs in each row. When i click on play button its background changes to pause button. What i want is when I click on play button in one row, the button that has background set to pause image on previous click should automatically change to play image and only the button which I has clicked should have pause background.
On click of button in a row of listview how to change other rows buttons background?
Regards,
Naresh T
I'll give you the basic idea of how you could implement this. You need to have a custom Adapter which would store the View which is currently set to "playing" state. Let's say, it would be called mCurPlaying. After the user clicks another View, change the background of the mCurPlaying and replace it with the newly clicked View.
Should you have any problems with implementing this, please, drop a note and I'll give you some more hints in code.
Instead of writing on click for whole row set only onclick for a button in that row in getview method of adapter class it solved your problem.
I was changing view when click button using Layoutinflater.The button have located in the same position in all the screen.
If i click button it change the view only once.If i double click the button it change the view twice.It means click event
dispatched twice in two different layouts.Here when i double click the button it should change only once.
For that what should i do?
Thnx,
You can take diff of two click events, that is store system time of first event in variable ( global scope) and diff it by system time of latest event. Here you need to decide time span between two click events oon the basis of which you consider wether its a double click or not. Say i consider if second click is done within 35 milliseconds of first click event, its a double click.
Thus if the time difference above is less than 35 seconds, you can restrict view change
Hope this would help u
I want to have the SlidingDrawer show in 2 parts. On the first swipe up it shows only 1 button. and in the other swipe up, it shows the second button.
How can I do this? Thanks.
You could always have a counter in the SlidingDrawer that counts how many times the user have opened the drawer. And depending on the counter you either choose another layout or just use
setVisibility on different views.
Simple example, lets say you have button1 the first time the user opens the drawer and button2 the second time. If the user draws it a third time set the counter to 0 again.
if(counter==0) {
button1.setVisibility(View.VISIBLE);
button2.setVisibility(View.GONE);
}
else {
button1.setVisibility(View.GONE);
button2.setVisibility(View.VISIBLE);
}
SlidingDrawer
For the counter you could use setOnDrawerCloseListener to change the value since you want to have the upcoming counter value before the user have opened the drawer.