Changing button text doesn't work? - java

I am having a problem with changing a button text. My application has 2 buttons. Button A accesses the internal memory/SDCARD directories on the phone(Filechooser activity). Once a file is selected, the filename of the selected file is stored in a Set list. Each file selected is stored in the set. At the same time, there is a variable counter that increments whenever a file is selected. The other button is the "Selected" button which display a ListView of the selected files. The problem is whenever I attempt to change the text for the Selected button so that it shows how many items was selected, the application crashes.
i.e: if 8 items were selected, the Selected button should be replaced with the text "Selected(8)".
Here is the code:
private void onFileClick(Option o){
selected.add(o.getName());
itemSelected = selected.size();
selectedList.setText("Selected("+itemSelected+")"); // the problem
}
Please if anyone can figure out a way to change that button text I would appreciate that.
Thanks in advance.

Related

How can I do this without starting any activity or fragment

How can I do this When User Click On the Next Button Activity Should not change only data should change for example if there is TextView then its data should change and so on.
I want output like This Gif
If you have any doubt please feel free to ask in the comments
I think this is able to do with the help of animation.
There are a couple of ways you can do this. You will need to have a list of data which will hold the title and the images. Then you can do one of the following
On your button click, change the text of your TextView and set the image resource of your ImageView by fetching the next item of the list manually each time.
You can use a ViewPager and update the current page when you click on the button
You can use a ViewFlipper and manually add Views based on your data and change views on button click
To achieve this view take on int counter with initial value 0 and use CountDownTimer method.
Create list which contains image and text values in model. on CountDownTimer method every tick you can increase the counter and set image and text again from the list index.

Change button color after updating text field

There are 20 JTextField and one calculate button in panel.
after entering data to text field and I click button, program calculate as well.
What I want to do, after first click for button, is there any updates in any text fields, button colors should be change as green (it means you have to know something already change and you have to calculate again).
How can I proceed with that, should I put action listener for each text field or any other short code exist?
Your question is not clear. As far my concern to yr question you can track button click event and put code there for check jtextfield value and on the bases of value you can take decision to change the color of the button

Checking if a button exists in java

I have some radio buttons and each one of then create a button with the Name "OK", such button is meant to proceed.
However, I need to check if the button already exists so the program don't create a copy of the button each time one of the radio buttons is clicked.
Check by the variable name. It won't allow you to create a variable with the same name...

I want to generate expandable list on click of button

In my application I am having 5 checkboxes for displaying different task on another activity
in this user have to select 1, 2 or 3 checkbox which he/she want to see on next screen.
In first screen i am having Save button. after checking checkboxes user have to click on save button.
My question is I want to show only those Expandable list on second activity which is selected by user on check box when user click on save button
please tell me how to do this?
Thank you very much.
save the selected check-boxs and then when you inflate the expandable listview adapter return views only for the selected ones
create dynamic array of selected Item, and assign this array to the group array

Can I show up the textbox editor on an image icon in Android?

all,
We know on Andorid, for a EditText, by default, whenever the EditText is clicked, the soft keyboard pops up to let you enter text. When you click DONE, it closes out and put the text directly to the EditText.
Now, what I am trying to do is, instead of an EditText, I have an ImageView which is to let user enter some comment.(So the ImageView actually is an comment icon). I wish whenever the icon is clicked, it pops up the text editor with user previous entered text, again once the DONE is hit, it closes out and I can save whatever text there back to a string member of the Activity. Is that possible?
So far, all I've seen about InputMethodManager is on EditText control, If it is too complicated, I probably just put an EditText into a sperate Activity.
Thanks.
There are many solutions:
One is to use custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Second one is to use a transparent activity on top of that one.
Then you could use FrameLayout and insert another view in an exact position...
I think you should try the frist or second one. Every ImageView can be easily converted into a button by adding onClick event to it.

Categories

Resources