We are about to switch to a new forum software. Until then we have removed the registration on this forum.
In this code bellow i tried to load different texts(defferent names) from a list after touching the "Details" button on my device..The problem is that it shows me the name only fore some seconds but i want to stay there invariably..
import ketai.ui.*;
import android.view.MotionEvent;
Button on_button; // the button
int clk = 1;
KetaiGesture gesture;
KetaiList klist;
KetaiList selectionlist;
ArrayList<String> textlist = new ArrayList<String>();
void setup() {
size(1000,600);
orientation(LANDSCAPE);
textSize(28);
textAlign(CENTER);
gesture = new KetaiGesture(this);
on_button = new Button("Details", 820, 420, 100, 50);
textlist.add("Patient 1");
textlist.add("Patient 2");
textlist.add("Patient 3");
textlist.add("Patient 4");
textlist.add("Patient 15");
}
void mousePressed()
{
if (on_button.MouseIsOver()) {
selectionlist = new KetaiList(this,textlist);
}
}
void onKetaiListSelection(KetaiList klist)
{
String selection = klist.getSelection();
if (selection == "Patient 1")
fill(150);
text("Kathy Smith",30,40);
if (selection == "Patient 2")
fill(150);
text("John Doe",30,40);
if (selection == "Patient 3")
fill(150);
text("Sue White",30,40);
// if (selection == "Patient 4")
}
void draw() {
background(255);
on_button.Draw();
}
// ==========================================================
class Button {
String label; // button label
float x; // top left corner x position
float y; // top left corner y position
float w; // width of button
float h; // height of button
// constructor
Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
label = labelB;
x = xpos;
y = ypos;
w = widthB;
h = heightB;
}
void Draw() {
fill(150);
stroke(141);
rect(x, y, w, h, 10);
textAlign(CENTER, CENTER);
fill(0);
text(label, x + (w / 2), y + (h / 2));
}
boolean MouseIsOver() {
if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
return true;
}
return false;
}
public boolean surfaceTouchEvent(MotionEvent event) {
// Call to keep mouseX and mouseY constants updated
//super.surfaceTouchEvent(event);
// Forward events
return gesture.surfaceTouchEvent(event);
}
}
Answers
@ermina===
some errors in your code (for testing strings dont use == but equals); and write your texts inside draw with a boolean; see the code below (i have added some methods in order that the list can be much more long: let us say 200 or 300 items!) without hardcoding; of course with this code you have to add texts (names) to each item: as it is when you click "patient 15" you will get the last selected! - create an arrayList for names also - Now i dont know what happens with ketail list when the number of items is a big number. As for me i would use android listView and scrollView and instead of putting the details as you do i would create a fragment for showing them.
Could you please show me a similar example with android listView and scrollView and instead of putting the details, to create a fragment for showing them, as you said??And what happens if i want to add a second button??Is the same way to do it???
@ermina===
first thing: put answered for others
second :try to elaborate some code for a listView: i have here put examples && snippets for textView, webview, videoView and for all Views it's the same way to use
then open a new topic with your code on the forum
as for a second button of course it is the same thing and it's easy as you have already a button class
If i add a second button with the same way and with a KetaiList also how will i manage a second onKetaiListSelection(KetaiList klist)??Only just with a change on the name klist???
@ermina===
sorry, i thought it was a button like your "details"; if it is for a list you have to create another instance of KetaiList called as you want and add to it some on selectionListener like for the first list; what i dont know because i dont use ketai is if you can parameter the lists (setting X...Y...and so on)... Yet i am not sure to understand exactly what you want! Try to explain better using your example.
For example i have made a programm which is in my discussions with the title of "ploting data". This programm loads csv files which are ECG signals, by pushing a button and make them plots.I was thinking about adding one more button like details to show some texts, names, etc...