Button OnCreate asset/resource at a different activity - javascript

Hello I have asked this question before but perhaps it wasn't clear or was deemed irrelevant but I need to figure out how to make a button OnClick create a button on another XML layout.
I am very new to java and coding in general and have looked for the past few days but can not find any information on how I would go about this.
The closest I could get was another users question on stackoverflow where the method of keeping the button I want to create invisible and having it switch visibility OnClick of original button, but this isn't feasible.
While this method would work for the single button I need to click to generate the other button, the place it would generate it will also generate a different variety of buttons from other sources. The only way this seems possible is to have the dozens of invisible buttons from each source already stored there and that doesn't seem like the most logical way to approach it code wise.
I would greatly appreciate any help in this area, I'm not expecting anyone to show me how it's done or write me sample code if you could simply nudge me in the direction of an online guide,tutorial or information source I'd be very grateful,
Thanks for your patience.

Creating Button programmatically and adding to the LinearLayout.
//First get the reference of LinearLayout where you need to add the buttons.
LinearLayout ll=(LinearLayout)findViewbyId(R.id.llayout);
// Layout Param
LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
/* This line of code to add the button in layout (implement your own logic i.e how many time you need to add the button and at which condition you need to add).*/
Button button = new Button(Context);
button.setText("dynamic button 1");
ll.addView(button,param);
Hope this achieve your goal.

Related

Multiple buttons function to expand and hide div section with javascript

Hope everyone is having fun on this fun (or frustrating šŸ˜‚ like me) coding day. So, I came across a problem and was hoping someone could help guide me to the right solution. I want to set it so that when I click on the ā€œread moreā€ button, it adds the ā€œactiveā€ class and would expand the paragraphs.
I was able to do a loop function for multiple buttons on the page, but when I click on one, it affects all the buttons. I know this is a looping problem but I have not figured out a way to solve it.
What Iā€™m trying to do is basically only have the button I click on add the class, without it working on all the buttons on the webpage. I intend to add more buttons to the page, so if anyone has a better solution or knows of a looping method (cause Iā€™m pretty sure the looping Iā€™m using is the wrong way), please help.
Please see the video for what I mean when I click on one button, both buttons get affected by it.

How to create a page location in browser using javascript/jQuery?

I have a setup where I display a list of buttons and clicking on the buttons triggers a function that contacts a firebase database and gets the contents of a 'slide' that is to be shown to the user. The function then clears the content of the page and then creates elements from the data acquired from the database.
Now obviously, when I press back browser button once I've replaced the content, it won't take me back to the previous content. But I believe that my user's experience will be much better if it actually took them back to the list of buttons. I have two faint ideas on how to go about solving this problem but I'm lacking in specific details of how I can go about it.
Possible Solution 1:
Some way to dynamically create a new page using javascript and then serve it to the user.
Possible Solution 2:
Some way to simulate that the page has changed location. Maybe using anchoring links.
Let me know if you have any other solutions in mind or if you know how I should go about implementing these. Your help will be much appreciated. :D

Saving information of a control in javascript app data

I'll try and ask this as accurate as possible as I don't exactly understand my assignment.
Basically we had to create 3 HTML controls or JS controls and for each control we had to add an event handler that'd read something from a control and show it in a DIV.
Now my question is, how can I save the information shown in that DIV. I really don't understand how to do this. To be more specific, when I close the Build and re-open it after typing something in a textbox that would for example then give me the info from the textbox in a DIV, i'd want to see the same information I typed earlier in the Div again.
Thanks in advance!

Hide/Disable Edit button based on column's Values in Sharepoint 2010

I have a column that has 2 Categories, Done and Pending. I would like to Hide/Disable edit button once the user selects an item and if that item has a Status column of "Pending".
I would like to know how can this be done, whether in visual studio 2010 or ECMA Scripts.
I know this question is old but if someone still needs the answer:
Create a custom action in visual studio like this:
https://msdn.microsoft.com/en-us/library/office/ff408060(v=office.14).aspx
This hides the button you want, now you can set a condition via enabledscript parameter to choose in which case the button should be hidden:
Just add this code after </CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="HideEditRibbon"
CommandAction="javascript:return true;" EnabledScript="javascript:checkIfNeedsToBeHidden();" />
</CommandUIHandlers>
<CustomAction Id="yourJsReference" Location="ScriptLink" ScriptSrc="yourJsFile.js"></CustomAction>
If you need this in List-Ribbon, Edit and DisplayForm, you need to make 3 Custom Actions and change the Location-Part and maybe your js-code.
If you want to use an out of the box edit form then you're not going to do this with server side code; you'd need an entirely custom edit form to do that.
This means using Javascript on the edit page, which is fragile, and doesn't prevent users from saving the data if they know what they're doing.
The input field for every column will have a 'title' attribute with the column name. JQuery can find the element with title='column name' rather easily, so that's how you'll know if you need to hide the save button. The save button isn't quite as easy to get to. You could try getting the input with type=button and value=save.
If it's important to have actual security around this, so that no matter what someone can't edit an item in this state then you can use an event receiver on the ItemUpdating event. Just check the properties of the item and use the properties.Cancel = true; (or something like that) so that even if they disable your JavaScript and save the event anyway, it won't get saved. If you need help adding an event receiver or getting it working just ask.
Edit: In your comment that you say you just want to prevent access to the edit form entirely under certain conditions. For that, I'd make a new webpart/user control and add it to the edit page. In that section you can fetch the appropriate item (the ID of the item will be a query parameter) and see if the page should be 'viewable'. If not, then you can redirect to another page.
Another addition to the above would be attempting to edit the list view such that there is no edit link for certain items. This would be substantially harder, and I doubt it would even be possible (practically) with out of the box webparts. You would need to have an entirely custom list view page in order to control which items have links to an edit page. (Others feel free to correct me here.)

Bookmarklet to select all friends and add them to an event on Facebook

I am trying to make a bookmarklet to allow me to select all my friends in the dialog to create an event on Facebook. Examining the source with Firebug shows the following:
The div container for each person gets a new class label of
selectedCheckable
when it it is clicked, So I have written this like of JS to try and select all the div's and give them this class:
$(".checkableListItem").addClass("selectedCheckable");
This works in selecting them, however when it comes time to press the "Save and close" button, the changes do not seem to have any effect in selecting all the friends to add to the event. It seems that FB has a different way of marking the friends that have been selected to add to the event. Would anyone be able to point me in the right direction so I can accomplish this? Thanks in advance, RayQuang :)
May I advise instead of making your own couldn't you just use one of these Greasmonkey scripts?
http://userscripts.org/scripts/search?q=facebook+invite&submit=
That's what I was doing and it was working for my events. Let me know if it works for you.

Categories