Get button from dataview on tap in Sencha 2 - sencha-touch

In my Sencha Touch 2.4.1 application, I have a dataview where each row has some text, and two buttons.
In my dataview, I have the following listener:
listeners: {
itemtap: function(dataview, index, target, record, e) {
// for testing
var el = Ext.fly(target);
var el2 = e.getTarget(null, null, true);
}
}
What I want to do is get the element that was tapped, and if it's a button, get that specific button and do something with it (like change its background color).
How can I get the specific button?
I have tried functions here and have tried to get the id and html of the element, but I've had no luck - usually the value or function is undefined. Tried e.target, el.dom...
How can I get the id, itemId, or cls of the button that was clicked?

You should use e.getTarget. For example, if your button has class "ux-dataview-button" then itemTap should be like this:
itemtap: function(dataview, index, target, record, e) {
if (e.getTarget('.ux-dataview-button')) {
// your code
} else {
// your code
}
}

Related

How to set cursor positioned on focused Entry tag in XAML?

I tried using the CursorPosition value but it doesn't appear to be working. The value is a single digit and the cursor needs to update to be in front of the digit when the value is tapped (or focused upon). Anyone know what might be the issue here?
public PaymentOccurrencesControl()
{
InitializeComponent();
PaymentNumberEntry.Focused += PaymentEntryField_Focused;
}
private void PaymentEntryField_Focused(object sender, FocusEventArgs e)
{
Device.BeginInvokeOnMainThread(() =>
{
PaymentNumberEntry.Focused += (s, e) =>
{
PaymentNumberEntry.CursorPosition = 1;
};
});
}
Wrap the code that sets CursorPosition in:
Device.BeginInvokeOnMainThread( () => {
…
});
This delays the cursor change until after xamarin and the phone’s OS have completed the focus action - which sets cursor position, overriding what you did.
ONLY wrap the line that sets cursor position:
public PaymentOccurrencesControl()
{
InitializeComponent();
PaymentNumberEntry.Focused += (s, e) =>
{
Device.BeginInvokeOnMainThread(() =>
{
PaymentNumberEntry.CursorPosition = 1;
};
});
}
Explanation: When the control gains focus, Android will begin executing your code after PaymentNumberEntry.Focused. It sees BeginInvoke, which tells Android "delay what's in here, until the current UI action (the control gaining focus) finishes". It queues this action:
() =>
{
PaymentNumberEntry.CursorPosition = 1;
};
This allows Android to do whatever it wants to CursorPosition (actually, to its native control's equivalent field). That's what makes the situation confusing - CursorPosition is not controlling the actual cursor position, until the next time it is given a value.
When it finishes, it returns to the MainThread loop, which looks for the next action to do. Which is your CursorPosition logic. Because your code runs last, it successfully updates Android's native cursor position.

How to draw some text when click a button in wxWidgets?

I want to draw some text when click a button. My code is:
#include <wx/wx.h>
enum
{
BUTTON_Hello = wxID_HIGHEST + 1
};
class myFrame : public wxFrame {
public:
wxButton* HelloWorld;
wxPanel* panel;
void OnPaint(wxCommandEvent& event) {
wxClientDC bdc =wxClientDC(this);
bdc.DrawText(wxString("Draw some text when button clicked."), wxPoint(300, 300));
Refresh();
};
myFrame(wxWindow* parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize) :
wxFrame(parent,id,title, pos, size) {
panel =new wxPanel(this, wxID_ANY, wxPoint(0,0),wxSize(100,100));
//Connect(wxEVT_PAINT, wxPaintEventHandler(myFrame::OnPaint));
HelloWorld = new wxButton(panel, BUTTON_Hello, _T("Hello World"),
wxPoint(5,5), wxSize(100, 100));
HelloWorld->Bind(wxEVT_BUTTON, &myFrame::OnPaint, this);
};
};
class MyApp : public wxApp
{
bool OnInit() {
frame = new myFrame((wxFrame*)NULL, -1, wxT("Hello wxDC"),
wxPoint(50, 50), wxSize(800, 600));
frame->Show();
return true;
};
wxFrame* frame;
public:
};
IMPLEMENT_APP(MyApp)
I define the drawing function in a wxFrame and bind it to a wxButton using Bind(). The drawing function uses a wxClientDC. I have added Refersh() to force updating wxFrame. The wxButton belongs to a wxPanel which is a child of wxFrame.
However, when I click the button, nothing happens and no text is shown.
You must use wxPaintDC when drawing in your wxEVT_PAINT handler, not wxClientDC. While wxClientDC also "works", at least for now and at least under some platforms, this is definitely not the right way to do it.
When using wxPaintDC, Refresh() would work as expected and will result in a call to your paint handler during the next event loop iteration. Normally you don't need to call Update(), which immediately calls your handler, at all.
I solved this problem by myself.
As wxPanel is the only child of wxFrame, it will automatically cover the whole area of wxFrame. Now drawing on wxFrame is necessarily having no effect. So I have to draw on wxPanel:
void paintNow(wxCommandEvent& event) {
wxClientDC bdc =wxClientDC(panel);
bdc.DrawText(wxString("Draw some texts when button clicked."),
wxPoint(300, 300));
//panel->Refresh();
panel->Update();
};
Also I find that if I use Refresh() and Update() simultaneously, no text will be shown.
If I only use Refresh(), no text will be shown.

How to make the start Snackbar message when you click on the menu?

How to make the start Snackbar message when you click on the menu?
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.reset):
number1.setText(null);
number2.setText(null);
//Snackbar.make(findViewById(android.R.id.content) , "Text", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
break;
case (R.id.quit):
finish();
break;
}
return super.onOptionsItemSelected(item);
}
It does not react.
You can use the main activity view to display the SnackBar :
Snackbar.make(this.findViewById(android.R.id.content),
"FooBar", Snackbar.LENGTH_LONG).setAction("Action", null).show();
When you click on menu item you can do like this:
Snackbar.make(getWindow().getDecorView(), .....);
Remember you MUST pass View object in order to show snackbar

XAML: Tap a textbox to enable?

In XAML and WinRT, Is there a way to set up a textbox so that it is disabled for text input until it is tapped.
I tried setting up the Tapped event and then setting the IsEnabled=true, but that only seems to work if the IsEnabled=true in the first place.
I found this on MSDN:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/708c0949-8b06-40ec-85fd-201139ca8b2d
Talks about adding the TappedEvent manually to the event handled for each TextBox, which is cumbersome, but also doesn't seem to work unless IsEnabled was already set to true.
Basically, I want a form where all textboxes display data but are disabled unless the user taps to enable the box and then type.
You can use IsReadOnly instead of IsEnabled to achieve what you are looking for. In addition, you can set up the tapped event handlers in code easily. I'm not sure if setting up handlers in code is a requirement for this to work, as you noted above; however, it does simplify things.
Here are the details.
In the constructor of your page class (here it is MainPage), call the setup function:
public MainPage()
{
this.InitializeComponent();
// call the setup for the textboxes
SetupTextBoxes();
}
Here is where we do the magic - make all textboxes on this page readonly and set up tap handler:
private void SetupTextBoxes()
{
var tbs = GetVisualChildren<TextBox>(this, true);
foreach (var tb in tbs)
{
tb.IsReadOnly = true;
tb.AddHandler(TappedEvent, new TappedEventHandler(tb_Tapped), true);
}
}
Utility function to get a list of all children of the given type (T) of the passed in parent.
private List<T> GetVisualChildren<T>(DependencyObject parent, bool recurse = true)
where T : DependencyObject
{
var children = new List<T>();
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
DependencyObject v = (DependencyObject)VisualTreeHelper.GetChild(parent, i);
var child = v as T;
if (child == null && recurse)
{
var myChildren = GetVisualChildren<T>(v, recurse);
children.AddRange(myChildren);
}
if (child != null)
children.Add(child);
}
return children;
}
Finally, the event handler. This enables each textbox when tapped.
private void tb_Tapped(object sender, TappedRoutedEventArgs e)
{
((TextBox)(sender)).IsReadOnly = false;
}

how to properly detect which mouse buttons are down in JavaFX

I've set a listener to my Pane so that it will detect mouse left and right buttons being down.
But when I hold left mouse button, then press right one, previous action seem to lose it's effect!
My code:
root.setOnMouseDragged(new EventHandler<MouseEvent>(){
#Override
public void handle(MouseEvent t) {
if(t.getButton() == MouseButton.PRIMARY) f1();
if(t.getButton() == MouseButton.SECONDARY) f2();
}
});
while holding LMB I have f1() running, but when I push RMB it seems like new event totally overwrites previous one: only f2() runs.
How can I separate this two events?
getButton() can return only one value at a time. And it's latest pressed button. If you need to detect multiple mouse down being pressed you need to use corresponding functions:
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent t) {
if (t.isPrimaryButtonDown()) {
System.out.println("rockets armed");
}
if (t.isSecondaryButtonDown()) {
System.out.println("autoaim engaged");
}
}
});