What is the Meaning of this code??specially View's role in it??it is an android code? - android-view

Code goes like this
Button next;
next =(Button) findViewById(R.id.button1);
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

There is a button called "next", it is really a rename of the already existing button R.id.button1 . The method that listens to click events (setOnClickListener) has a method that gets called when the button is actually clicked (onClick), within "onClick(View v)" you want to put all the things that you want the program to do when the button is clicked.

Related

ICommand not always firing when tab selected

I have a simple ActionBar with 3 tabs attached. When a tab is clicked, the fragment is inflated and the view shows. The tab being click event is fired using an event. Initially, the first fragment is inflated, but the others respond and inflate if clicked.
If I change the event being fired to an ICommand, only the last fragment is inflated and then if I click on the first tab, that and the last are inflated. Never the second.
My code is this
ICommand TabClicked
{
get
{
return new RelayCommand(() =>
{
tab.TabSelected += (object sender, ActionBar.TabEventArgs e) => TabOnTabSelected(sender, e);
});
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
fragments.Add(new TODFragment());
fragments.Add(new ConditionsFragment());
fragments.Add(new ResultsFragment());
AddTabToActionBar("Time", Resource.Drawable.crucifix_colour);
AddTabToActionBar("Conditions", Resource.Drawable.weather_colour);
AddTabToActionBar("Results", Resource.Drawable.tod_colour);
}
void AddTabToActionBar(string text, int iconResourceId)
{
tab = ActionBar.NewTab().SetTag(text).SetText(text).SetIcon(iconResourceId);
/* uncomment and comment out one of the two below to see the difference in operation */
tab.TabSelected += TabOnTabSelected;
//tab.SetCommand<ActionBar.TabEventArgs>("TabSelected", TabClicked);
ActionBar.AddTab(tab);
}
void TabOnTabSelected(object sender, ActionBar.TabEventArgs tabEventArgs)
{
var tabNo = sender as ActionBar.Tab;
var frag = fragments[tabNo.Position];
tabEventArgs.FragmentTransaction.Replace(Resource.Id.frameLayout1, frag);
}
Am I missing something fundamental here in the difference between ICommands and Events or is it something else?
I'm using Xam.Android and MVVMLight
I found the answer. When I create the partial class I define the UI objects like this (or something like this at least)
EditText myEditText;
EditText MyEditText = myEditText ?? (view.FindViewById<EditText>(Resources.Id.myEdit);
This is fine, but it does mean that once defined, it doesn't get redefined.
Not a problem if the UI is not really going to change, but every time an action tab is pressed, the fragment is refreshed. Only problem is the Id isn't changing as myEditText is not null.
The answer is add a method in the UI definition code that nulls the objects then in the main code, when the UI disappears, call the nulling method. Everything works then

After clicking a button, how do I wait for SwingWorker to finish before proceeding?

I have the following code:
public class FileLoader extends SwingWorker(Void, Void) {
#Override
private Void doInBackground() {
loadFiles();
}
}
public class LogInPage {
private FileLoader fileLoader = new FileLoader();
public LogInPage() {
fileLoader.execute();
}
loginButtonActionPerformed(ActionEvent evt) {
//wait for files to finish loading
//while displaying a waiting cursor
showMainForm();
}
}
My question would be:
After clicking the button, I would want all the files to be loaded first (while displaying an hourglass cursor and progress bar) before showing the main form.
I have done this before with Thread's join() but was not able to do the same with SwingWorker.
I have read about overriding done() and implementing listeners but I can't apply it here.
Any help?
Thanks.
From what you're saying and contrary to what you think, I think you can actually use SwingWorker's done() method. Before execute(), disable the button, start a busy animation, whatever, then in the done() method, do whatever it is you need to do to continue the program. That's what it's for :-)
You should also look at the SwingWorker.publish() and process() to send and receive the progress bar events.
See also: How do I wait for a SwingWorker's doInBackground() method?

Add field manager to application Main screen in BlackBerry

I am working with a BlackBerry application for OS 5.0 and later. The application has one screen which displays at the top of screen a Next and a Previous button. and list field also display in this screen at bottom of these both button
When i click on NEXT Button and Previous Button my List will be updated display data..
When i click on NEXT/PREVIOUS Button i have to display small VerticalfieldManager at the center of the screen with Label "Please wait ..." so after design this screen how can we add more field manager in over the another manager ?
Is there any way to display that Field at the application MainScreen like iPhone AppDelegate screen?
btnState.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{ vfm_Middle.add(lblPleasewait);
popup = new PopupScreen(manager);
Thread thread = new Thread()
{
public void run()
{
try
{
Updatelistfield();
stop();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
super.run();
}
public synchronized void stop()
{
// TODO Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// TODO Auto-generated method stub
//popup.delete(vfm_Main);
//popup.deleteAll();
//vfm_Main.delete(lblPleasewait);
//lblPleasewait.setText(null);
}
});
}
};
thread.start();
}
});
The proper way of doing that is with a blocking dialog. In BB API this can be done as follows:
VerticalFieldManager manager = new VerticalFieldManager();
manager.add(new LabelField("Please Wait..."));
Screen popup = new PopupScreen(manager);
//Show the pop-up the same way you push a regular screen
This has the advantage of blocking the GUI: if the user pushes the menu or esc key it doesn't have any effect.
If you want to do it in your screen without dialogs, then you can add an empty VerticalFieldManager which you can fill with a label when the message has to be shown. This way, instead of updating the entire screen, only the Manager is refreshed. But then you should write the logic to not letting the user push any button or menu key (or ignoring key press).

blackberry react to menuitem

I started writing a bb app with a menu.
My problem is I don't know how to react if the selected item is clicked. The menu contains some fields in a VerticalFieldManager that is added in a class that extends MainScreen.
I'm sorry for asking such basic stuff, but i googled 1.5 hours now and didnt find a solution or example, Its my very first blackberry app.
Here you go.
This snippet of code defines a new menu item, with a constructor where you specify the label of the menu item and its position on the menu, and a run method which is called when the user clicks on your menu item.
The run method is called on the UI (event) thread, so you are free to update your user interface components from here, or do whatever else you need to do.
I also included a snippet of a screen class that adds the menu item to its menu.
final class MyMenuItem extends MenuItem
{
MyMenuItem()
{
super("Menu item text", 100000, 0);
}
public void run()
{
// The user has clicked on the menu item, and
// this method was called. Do what you need to do.
}
}
final class MyScreen extends MainScreen
{
// ...
protected void makeMenu ( Menu menu, int instance )
{
// let the system build a default menu first
super.makeMenu(menu, instance);
// add your menu item to the screen
menu.add ( new MyMenuItem() );
}
// ...
}

Blackberry screen navigation

I want to know how to go from one screen to another by clicking a button that I have added to a MainScreen. I mean just like we do in the Android onClick event for a button - start another startActivity.
In the event handler for the button click, just "push" the screen that you want to appear next, and it will be pushed to the top of the screen stack. For example:
UiApplication.getUiApplication().pushScreen(nextScreen);
This will be better, using FieldChangeListener
button.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
UiApplication.getUiApplication().pushScreen(new NextScreen());
}
});
This is the alternative way than using,
UiApplication.getUiApplication.involeLater()
{};

Resources