Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have 1 ajax button and 1 link:
AjaxButton buttonA = new AjaxButton("buttonA") {
private static final long serialVersionUID = 1L;
#Override
protected void onSubmit(AjaxRequestTarget target) {
info("buttonA");
}
}
Link<void> buttonB = new Link<void>("buttonB") {
...
}
I want to when I click buttonB is equivalent to buttonA click
Please help me.
Extract the body of ButtonA#onSubmit() to a separate method and just call this method in ButtonB#onClick()
private void doWork() {...}
AjaxButton buttonA = new AjaxButton("buttonA") {
#Override
protected void onSubmit(AjaxRequestTarget target) {
doWork();
}
}
Link<void> buttonB = new Link<void>("buttonB") {
#Override public void onClick() {
doWork();
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
link
link2
i follow both link but image lazy load not working in my project ,please suggestion
Here is working Example
image list api
https://picsum.photos/list
constructor(public navCtrl: NavController, public imageloader: Lorem) {
this.loadMyImages();
}
loadMyImages()
{
this.loadingLoremPicsList = true;
this.loremList = [];
this.albumList = [];
this.imageloader.getMyPics().subscribe(
data => {
this.loremList = data;
this.albumList = this.loremList.splice(this.getRandomInt(0, 700), 12);
console.dirxml(this.loremList);
this.loadingLoremPicsList = false;
},
err =>
{
}
)
}
in provider .ts
private my_lorem_pics: string = "https://picsum.photos/list";
constructor(public http: HttpClient) {
}
getMyPics()
{
return this.http.get(this.my_lorem_pics);
}
i need to update a textView from my asynctask. I have an custom adapter for the listview and there i want to have a countdown for each entry. I will start the asynctask for each entry from my Adapter. How can i update the textview each second from the asynctask?
Thanks for help :)
If you post your code, I can give you a better answer. However, a common way to update views periodically is by using Handlers.
private final Handler mHandler = new Handler(); //intialize in main thread
public void test() {
mHandler.postDelayed(new Runnable() {
#Override
public void run() {
mTextView.setText("hello");
}
}, 1000);
}
You can do something like this (this will add an entry to a list view every one second). I have used the normal ArrayAdapter to add a string. You can use your custom adapter to do something similar. The publishProgress() method basically triggers the onProgressUpdate() method which hooks to the UI thread and displays the elements getting added.:
class AddStringTask extends AsyncTask {
#Override
protected Void doInBackground(Void... params) {
for(String item : items) {
publishProgress(item);
SystemClock.sleep(1000);
}
return null;
}
#Override
protected void onProgressUpdate(String... item) {
adapter.add(item[0]);
}
#Override
protected void onPostExecute(Void unused) {
Toast.makeText(getActivity(), "Done adding string item", Toast.LENGTH_SHORT).show();
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
I am having trouble when I am trying to run my simple android applications On my system
I tested for some other applications which were not created on my system and those worked well but when I edit those on my system then also these applications wont work. I am getting many errors
09-26 07:23:55.458: E/AndroidRuntime(1341): ... 11 more
at com.calculation.MainActivity.<init>(MainActivity.java:19)
at java.lang.Class.newInstanceImpl(Native Method)
: at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
Why am I getting this
Please Help me
package com.calculation;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class MainActivity extends Activity {
EditText value1,value2;
Button add;
TextView display;
int num1=0, num2=0, total=0;
final AlertDialog alertdialog= new AlertDialog.Builder(MainActivity.this).create();
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
value1=(EditText)findViewById(R.id.input1);
value2=(EditText)findViewById(R.id.input2);
add=(Button)findViewById(R.id.btnadd);
display=(TextView)findViewById(R.id.result);
if(value1==null)
{
alertdialog.setTitle("AlertDialog");
alertdialog.setMessage("Please Enter a Valid Input");
alertdialog.setIcon(R.drawable.ic_launcher);
alertdialog.setButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "You Clicked OK" , Toast.LENGTH_LONG).show();
}
});
}
else if(value2==null)
{
alertdialog.setTitle("AlertDialog");
alertdialog.setMessage("Please Enter a Valid Input");
alertdialog.setIcon(R.drawable.ic_launcher);
alertdialog.setButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "You Clicked OK" , Toast.LENGTH_LONG).show();
}
});
}
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
num1=Integer.parseInt(value1.getText().toString());
num2=Integer.parseInt(value2.getText().toString());
total=num1+num2;
display.setText("ADDITION IS"+total);
}
});
}
}
The Problem was of api levels the apps which were tested were created many years back in different api level and environment so the alert dialog error was coming
alert dialog can be in this way
private void showinvalidemail() {
// TODO Auto-generated method stub
AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
dialogbuilder.setTitle("Invalid Email");
dialogbuilder.setMessage("Please Enter Valid Email");
dialogbuilder.setIcon(R.drawable.mexit);
dialogbuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
// TODOAuto-generated method stub
Toast.makeText(getApplicationContext(),
"You Clicked OK", Toast.LENGTH_LONG).show();
}
});
AlertDialog alertdialog = dialogbuilder.create();
alertdialog.show();
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to perform an event when I click on a panel, in the same way this happens when the user clicks on a button.
I need this in order to handle events on click for this panel.
You have to use GWT FocusPanel which makes its contents focusable, and adds the ability to catch mouse and keyboard events. So wrap your panel inside FocusPanel.
Panel panel = new Panel(); //Your panel here(ex;hPanel,vPanel)
FocusPanel focusPanel = new FocusPanel();
focusPanel.addClickListener(new ClickListener(){
public void onClick(Widget sender) {
// TODO Auto-generated method stub
}
});
focusPanel.add(panel);
One more possibility(without FocusPanel)
HorizontalPanel hpanel = new HorizontalPanel();
hpanel.sinkEvents(Event.CLICK);
hpanel.addHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
}
}, ClickEvent.getType());
I would make a new widget ( extending in this example an Absolute panel ) that implements the HasClickHandlers interface like this
public class MyCustomPanel extends AbsolutePanel
implements HasClickHandlers
{
public HandlerRegistration addClickHandler(
ClickHandler handler)
{
return addDomHandler(handler, ClickEvent.getType());
}
}
And then in my code I would do it like this
MyCustomPanel mPanel = new MyCustomPanel();
mPanel.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// Do on click stuff here.
}
});
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Can anybody suggest me how to create a clickable list field in blackberry such that on clicking one item a new screen must appear.
I've done a similar work with VerticalFieldManager and custom extended Field on JDE 5.0.
I assume that you have a list of objects that you wanted to display on main screen.
First; create a class which extends Field for your list's item, override its paint method, layout method and otuher events as your requirements.
Next, create a main screen that you wanted to show the list. Once you have populated your object list, in a loop, pass each object model to previously created field's constructor. Then add fieldChanged event to that field and add it to verticalFieldManager.
You need to override the events (like fieldChanged event) as you want to click on it and display its detail on another screen.
Finally, create a detail screen that takes required arguments to display your list item's object detail. On fieldChanged event of your main screen implementation, pass your object to detail screen and push the detail screen.
Also, this approach may be useful for you.
Example:
custom field:
public class CListItemField extends Field {
private CListItemModel model;
public CListItemField(CListItemModel _model, long style) {
super(style);
this.model = _model;
}
public CListItemModel getModel() {
return this.model;
}
// overrides
public int getPreferredHeight() {
//return custom height
}
public int getPreferredWidth() {
//return custom width
}
protected void layout(int width, int height) {
setExtent(Math.min(width, getPreferredWidth()), getPreferredHeight());
}
protected void paint(Graphics g) {
//custom paint stuff (borders, fontstyle, text position, icons etc.)
if (isFocus()) {
//focused item display settings
} else {
//item display settings
}
}
protected void drawFocus(Graphics graphics, boolean on) {
}
public boolean isFocusable() {
return true;
}
protected void onFocus(int direction) {
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean keyChar(char character, int status, int time) {
//send key event to listener
if (character == Keypad.KEY_ENTER) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}
list screen:
public class ScreenListbox extends MainScreen implements FieldChangeListener, FocusChangeListener {
private VerticalFieldManager verticalField;
private Vector listItemVector;
public ScreenOttoInbox(String title) {
super(title, Manager.NO_VERTICAL_SCROLL);
setData();
setComponents();
}
private void setData() {
//populate listItemVector according to your business (ie. read json response then parse it and collect it to a vector)
}
public void setComponents() {
verticalField = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
setListContent(verticalField, listItemVector);
add(verticalField);
}
private void setListContent(VerticalFieldManager field, Vector vector) {
try {
int vlen = vector.size();
for (int i = 0; i < vlen; i++) {
CListItemModel model = (CListItemModel) vector.elementAt(i);
CListItemField itemField = new CListItemField(model, Field.FOCUSABLE | Field.ACTION_INVOKE);
itemField.setChangeListener(this);
itemField.setFocusListener(this);
field.add(itemField);
}
} catch (Exception ex) { }
}
protected boolean onSavePrompt() {
return true;
}
public void fieldChanged(Field field, int context) {
//custom field's click/touch event handler
CListItemField itemField = (CListItemField) field;
ScreenItemDetail scrDetail = new ScreenItemDetail(itemField.getModel());
ScreenUtil.pushScreenWithLoader(scrDetail,true);
}
protected void onDisplay() {
super.onDisplay();
}
}
Create a class like below.
import java.util.Vector;
import net.rim.device.api.collection.util.SparseList;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
public class CListCallback implements ListFieldCallback {
private String[] resource;
private int rgb=Color.BLACK;
Vector elements;
Bitmap arraow;
public CListCallback(String[] resources){
this.resource=resources;
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
String text=(String) get(listField, index);
graphics.setColor(rgb);
graphics.drawText(text,60,y+25);
graphics.drawLine(0, y+59, DConfig.disWidth, y+59);
}
public Object get(ListField listField, int index) {
return resource[index];
}
public int getPreferredWidth(ListField listField) {
return DConfig.disWidth+10;
}
public int indexOfList(ListField listField, String prefix, int start) {
return -1;
}
}
And use above class in MainScreen class.
CListCallback clmenu=new CListCallback(arrayitems);
final ListField lf = new ListField(arraymenu.length) {
protected boolean keyChar(char character, int status, int time) {
if (character == Keypad.KEY_ENTER) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
protected boolean navigationUnclick(int status, int time) {
fieldChangeNotify(0);
return true;
}
};
lf.setCallback(clmenu);
lf.setRowHeight(60);
lf.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
int index=lf.getSelectedIndex();
UiApplication.getUiApplication.pushScreen(newNewScreen(imgarray[index]));
}
});
add(lf);
Thats it.it will work