So the situation is that I have a bluetooth class where I get some values, I want to display those values inside the UI, but for some reason I can't figure out how to do it. In swift I would do it with an observable object, but in Kotlin I couldnt really find something similar, or I could at least not get it to work. Is there an easy way to do this (setting UI from a class?) and is there something special I have to do inside the class?
I was quite dumbfounded by how difficult it is / how hard it is to find how to do it. I have things like and more
val textView = findViewById<TextView>(R.id.NewText)
textView.text = "Changed from class"
I also tried setting that inside
lifecycleScope.launch(Dispatchers.Main) {
}
and inside
runOnUiThread{}
both crashed!
I have tried doing somethings with binding and researched quite a bit and I just can't figure it out.
I saw some thing with something called kapt, but that is old I Believe?
Any help would be appreciated, thanks in advance.
Related
Relatively new to coding and have taken up lots of small projects to help learn the basics, and I have now set myself a challenge of a "bigger" one. Essentially I want to recreate the Message Box but with my own styling and customisable elements.
I have got the basics in a class and created it, however I want the class to have two options.
1) load all the details from an XML file for the message, I have done this and that works.
2) I want it to be like the standard message box where you can pass in parameters.
My question is, How can I achieve number 2.
I have tried adding details into the Show/Load subs but no luck, the only way around it I can see is with properties but that would take too long.
I want to be something like the below.
classname.show("message","tittle",icon,"buttons",imagefile,"caption")
However alot of my code is done in the load method as opposed to show, so it needs to be visible / accessible there.
Any help / advice would be appreciated.
Properties are definitely the way to go. It also makes sense: Conceptually, the message being shown is a property of the message box.
Your Show method would look like this:
Public Shared Show(message As String, title As String, ...)
Dim box as New MyMessageBoxWindow()
box.Message = message
box.Title = title
...
box.ShowDialog()
End Sub
In the Load method of MyMessageBoxWindow, you access these properties and configure the UI elements.
Is the source for Windows Store (WinRT) UI controls publicly available? We would like to extend some of the controls and not have to start completely from scratch, like we can for SL and WPF. Googling and looking through SO doesn't turn up anything for Windows 8.
Thanks!
So unlike WPF, [WinRT-XAML] controls are written in C++/CX.
But, it sounds not so much like you want the source code as much as you want to derive from existing controls and extend or override their functionality. You know you can do this, right? It's easy enough and sounds like you will get the results you are asking in your question.
Something like this:
public class MonkeyTextBox : TextBox
{
public new string Text
{
get
{
return "Always Monkeys!";
}
set { /* do nothing */ }
}
}
This is my custom TextBox wherein I have replaced the base implementation of Text with my own. Granted, I hope your custom controls are better. Anyway, you can do this with almost every control, and you can add your own properties and events. Make sense?
Reference: http://blog.jerrynixon.com/2013/01/walkthrough-custom-control-in-xaml-isnt.html
But to answer your question: no, we have not released the source (yet). Hopefully, that will save you the time looking for it. Maybe someday we will - maybe.
Best of luck!
I have a cocoa app that allows the user to enter a query. I'm using an NSWebView with a TextArea HTML object. The problem is, as soon as I type anything into the textarea, my document gets marked as updated. Does anyone know of a way to prevent this?
I've verified that using a NSTextField does not reproduce this behaviour, but I specifically want to go with the HTML/TextArea for styling.
So basically: Can I make it so an NSDocument does not get marked as edited unless I manually call:
[document updateChangeCount: NSChangeDone];
This post on the Apple mailing list seems to match your problem exactly.
The solution suggested is to set a custom undo manager to the webview (sounds like hard work), however a quick-and-dirty hack looks to me like subclassing updateChangeCount and perverting things to your way of thinking.
I want to create a new object so as to instantiate and use it several times;
For example, if I want to create an object that has a label and a button inside, how do I? I created a new NSObject but inside it has nothing, then how do I make everything from scratch since there was a viewDidLoad for example (obviously, since it has a view)?
thanks!
Your questions lead me to think that you're really just starting out. There's nothing wrong with that, but rather than trying to summarize several megabytes of documentation in a few paragraphs, I'm just going to point you to the iOS Starting Point. I think that you're just trying to create a container that can hold other UI components? If so, use a UIView for that. However, don't jump in and try to get something specific done without first reading through some of the Getting Started documents -- you'll just end up back here, and we'll just point you back to the docs. You might like the Your First iOS Application guide, as that lets you get your feet wet but explains things along the way.
I am sure this question has been asked before, but I searched and couldn't find it so I apologize in advance for duplicating content here on SO.
That being said: In Objective-C, in an overridden method you can call the parent class method using something like [super methodName]
but how do prevent the rest of the code from executing in the child class from the parent? It could because it's Friday, but I stared at my monitor for a few minutes and couldn't get past it in my head.
Example (in child class):
- (void)methodName
{
[super methodName];
//Everything below this line shouldn't execute if tell it not to from the parent
NSString *aString = #"This should never be called.";
}
Help me out! I know there's a simple solution, but my brain just isn't picking it up today...
You could maybe have another function returning True/False which you use to decide if you wanna proceed with the remaining code in the child. This 'control' function can depend on a variable set in the parent class
Having said that, it sounds like an interesting requirement to me. Maybe you need to take another look at your class design and hierarchy.
you could test the object type and determine if you do or don't want to run additional code for example:
if (![myObject isKindOfClass:[MyChildObject class]]
{
//run only superclass code
}
As I write this, I can't help but wonder if you don't have some issue with how you setup your classes though. If your design is spot on, you shouldn't have to go through these kinds of contortions.