I am working on a simple Android Activity which contain 10 images and 2 Buttons i.e. "Next" and "Previous", i changed all images by click on "next" and "Previous" Button using an array and both Buttons showing on every images but i want to don't show "Previous" button when user at first image and same as don't show "Next" button when user reached at tenth (last) image.
You have to use loop for this. When you on first activity make visibility of previous button hide. On last activity make next button invisible. You can make button invisible using-
btnName.setVisibility(View.INVISIBLE);
For making visible when you on second or second last image-
btnName.setVisibility(View.VISIBLE);
loop
{
if(i==0){
btnPrev.setVisibile(View.GONE);}
else
{
btnPrev.setVisibile(View.Visible)}
if(i==array.getSize()-1)
{
btnNext.setVisibile(View.GONE)};
else
{ btnNext.setVisibile(View.VISIBLE)}
Related
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.
This is my first project in android and I want to display something like this in list view
Any advice is appreciated
You can go through CustomListView example.it can be done easily.
Please go through the Link below
how to customize listview row android
For achieving this layout you should use custom listview for that like it.
A row with one text view and four button mean five object in each row but show only two object one is textview and another is one button out or four button.
If you want to display fourth button then invisible first there button and fourth button in visible state.
If you want to display second button then first, third and fourth button invisible state only second button in visible state.
Fallow this logic in each row.
I hope you got you answer after using this logic.
I have a page which contains a listview alone. Upon clicking a row in the list, the next page is loaded. This next page contains a set of buttons. Upon clicking a row in the list, the loading of the next page may take sometime. So if someone is continuously clicking the row then at some point of time, the second page comes and the buttons inside that gets clicked, which I dont require. How can I prevent this clicking of buttons? Can someone help me out. Thanks in advance.
Use AsyncTask concept to load data for next activity, do as follow:
set setEnabled(false) to all buttons inside the onPreExecute() method.
do all the background task inside the doInBackground() method.
and now again setEnabled(true) to all the buttons so that it become enabled and user can click on the buttons.
Besides the fact that your activities shouldn't take that long to load initially, you could just set a boolean when startActivity() is called to start the new activity. Then check that boolean if the user clicks anything else before the next activity is loaded.
if(document.readyState==complete) //NB this property is not supported by firefox
{
//Activate buttons
}
i think you need to false click event and true while you want to use
like this::
button1.setClickable(false);
and when you want to enable just write
button1.setClickable(true);
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.
Activity1 has a listView. Clicking one item (let's say item 3) will start Activity2. Activity2 have a back button once clicked will bring user back to Activity1. What I want to achieve is to highlight the item 3 when user back to Activity1 so that the user have a sense where to continue. (May be i need to set the focus to item 3 as well.)
EDIT: Following code works.
public void onResume()
{
super.onResume();
//lastSelectedPosition saved in OnItemClickListener
lv.setSelection(lastSelectedPosition);
lv.requestFocusFromTouch();
}
well its pretty simple. just save the clicked item position of the list to a field when the list is clicked to launch your new activity.
Afterwards in the onResume() method just use myList.setSelection(savedPosition);
as for the highlighting, well focus works kinda bad especially if you have a bit more complex rows(buttons,checkboxes etc) and other ui elements beside the list that can take away the focus. i believe the best way to achieve this is just set the background of that particullar item onResume to the highlighted one and override onScroll listener to just change the background to your default when the list is scrolled. indeed its a workaround but it will work in 100% of the cases opposite to just focusing an item. plus maybe you can add animations on the view so you can make it look really nice and smooth.