Same Button in different line robotium - tablet

I'm writing robotium scripts for my tablet application. In line number 1 and 2 (on clicking line number 1 the next listview will appear with line number 2), there were same button "Go next" with same id. How do i click the "Go next" button in line number 2.
Thanks for the help.,
Dhivya.

Methods which should help you are as follows:
getView(int id, int index) // returns View
getView(String id, int index) // returns View
clickOnView(View view)
clickOnText(String text, int match) // match seems to be an index in this case

Try this:
int count = 1;
ArrayList<Button> bottoni = solo.getCurrentViews(Button.class);
for (Button button : bottoni) {
if(button.getId() == solo.getView("com.xxx.yyyyyyyy:id/idButton").getId())
{
if(count==2){
solo.clickOnView(button);
break;
}
count++;
}
}

Related

Flutter - PageView animatedToPage will load middle page. How to avoid it?

I have a PageView, I want scroll pageView programmatically, so I have two choices:
use animateToPage
use jumpToPage
now, I need smooth transition effect, so I have to use first api. But, I have a problem: animateToPage will load middle pages which don't need to be shown at this time when I scroll from the first page to the last page.(jumpToPage don't have this problem, but I need animation).
How to avoid it?
We can achieve that by
Swap lastPage Widget to next position of current page
Animate to next page
Jump to real lastPage index
Refresh swapped Index to its previous value
In this example, I used fixed PageView children count, which is 8.
Demo
Comparison
Combine to 8th page Button
as CopsOnRoad suggested, this button will trigger Scroll animation to last page (in this case 8th page). Firstly, we
jumpToPage(6), and then animateToPage(7, ..).
This method works, but adversely, user will notice sudden change of current page to 7th page.
Flash Jump to 8th page Button
Unlike like first method, this button will avoid displaying 7th page unnecessarily
Syntax Explanation
this is the main function
void flashToEight() async {
int pageCurrent = pageController.page.round();
int pageTarget = 7;
if (pageCurrent == pageTarget){
return;
}
swapChildren(pageCurrent, pageTarget); // Step # 1
await quickJump(pageCurrent, pageTarget); // Step # 2 and # 3
WidgetsBinding.instance.addPostFrameCallback(refreshChildren); // Step # 4
}
detailed look
// Step # 1
void swapChildren(int pageCurrent, int pageTarget) {
List<Widget> newVisiblePageViews = [];
newVisiblePageViews.addAll(pageViews);
if (pageTarget > pageCurrent) {
newVisiblePageViews[pageCurrent + 1] = visiblePageViews[pageTarget];
} else if (pageTarget < pageCurrent) {
newVisiblePageViews[pageCurrent - 1] = visiblePageViews[pageTarget];
}
setState(() {
visiblePageViews = newVisiblePageViews;
});
}
// Step # 2 and # 3
Future quickJump(int pageCurrent, int pageTarget) async {
int quickJumpTarget;
if (pageTarget > pageCurrent) {
quickJumpTarget = pageCurrent + 1;
} else if (pageTarget < pageCurrent) {
quickJumpTarget = pageCurrent - 1;
}
await pageController.animateToPage(
quickJumpTarget,
curve: Curves.easeIn,
duration: Duration(seconds: 1),
);
pageController.jumpToPage(pageTarget);
}
// Step # 4
List<Widget> createPageContents() {
return <Widget>[
PageContent(1),
PageContent(2),
PageContent(3),
PageContent(4),
PageContent(5),
PageContent(6),
PageContent(7),
PageContent(8),
];
}
void refreshChildren(Duration duration) {
setState(() {
visiblePageViews = createPageContents();
});
}
Full Working-Example Repository
You may look into full source code and build locally. Github

How to load data in TabbedPage when a tab is clicked?

I am using TabbedPage for navigation with tabs. All my Page classes have just an empty default constructor and I load my data in the OnAppearing method. I have 5 tabs. As soon as I click on the second tab, the OnAppearing methods of the 3rd, 4th and 5th pages are also called.
How do I ensure that the data is only loaded when I click on the tab?
Solution:
You can get the index of currentPage in method OnCurrentPageChanged And if the index equals 1(second page) , use the messagecenter to send message to the page.Refer the following code .
in Tabbed Page
protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
int index = Children.IndexOf(CurrentPage);
if (index == 1)
{
MessagingCenter.Send<Object>(this, "click_second_tab");
}
else if (index == 2)
{
MessagingCenter.Send<Object>(this, "click_third_tab");
}
}
in the second page .Move the code that load data from onAppearing to the constructor
public MyPage1()
{
//...
MessagingCenter.Subscribe<Object>(this, "click_second_tab", (obj) =>
{
//load your data here
Console.WriteLine("11111");
});
}

How to populate Qtablewidget with editable item and none editable item

every body
i have a problem in populating Qtablewidget with editable items for the first row , and then
non editable items for the rest of rows her is my implementation so far
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTableWidgetItem>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTableWidgetItem *item= NULL;
for(int row=0; row < ui->tableWidget->rowCount(); row++)
{
for (int col=0; col< ui->tableWidget->columnCount(); col++)
{
if(row == 1)
{
item = new QTableWidgetItem;
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled);
ui->tableWidget->setItem(row,col,item);
}else{
item = new QTableWidgetItem;
item->setFlags(Qt::NoItemFlags);
ui->tableWidget->setItem(row,col,item);
}
}
}
}
MainWindow::~MainWindow()
{
delete ui;
}
Also, you need to set number of rows and columns before populating tableWidget:
ui->tableWidget->setRowCount(numberOfRows) and
ui->tableWidget->setColumnCount(numberOfColumnss)
Since you do not know how many rows you'll need (because you want the user to have the ability to edit lines from line to line infinity) I would do it like this:
ui->tableWidget->setRowCount(2);
...add only 2 rows ("line zero and one"), so user will have visible only two lines that he must fill. You'll need mechanism to check if all cells are filled (for example: every time cell item isChanged you check all other items if they are filled - not empty) so only when they are, user will be able to pass to editing new line, which you will add to table dynamically for every next row like this:
rowNumber = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowNumber);
for (int col=0; col< ui->tableWidget->columnCount(); col++){
item = new QTableWidgetItem;
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled);
ui->tableWidget->setItem(rowNumber ,col,item);
}
I hope this helps.

GTK+ How do I find which radio button is selected?

The tutorial here http://developer.gnome.org/gtk-tutorial/2.90/x542.html
shows how to set up the radio buttons, but neglects to tell you how to use them.
How do I then find which radio button is selected?
My solution:
Initialise radio buttons with:
rbutton1 = gtk_radio_button_new_with_label(NULL, "button1");
gtk_box_pack_start(GTK_BOX(rbutton_box), rbutton1, TRUE, TRUE, 0);
rbuttonGroup = gtk_radio_button_get_group(GTK_RADIO_BUTTON(rbutton1)); /*not sure what I'd use this line for currently though*/
rbutton2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(rbutton1), "button 2");
gtk_box_pack_start(GTK_BOX(rbutton_box), rbutton2, TRUE, TRUE, 0);
rbutton3 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(rbutton1), "button 3");
gtk_box_pack_start(GTK_BOX(rbutton_box), rbutton3, TRUE, TRUE, 0);
And update a variable telling you which radio button is selected with this method:
void checkRadioButtons()
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(rbutton1))==TRUE) selectedRadioButton =1;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(rbutton2))==TRUE) selectedRadioButton =2;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(rbutton3))==TRUE) selectedRadioButton =3;
}
Google brought me here for python / pygtk / pygtk3 searches, so I hope its okay that I post a pygtk solution:
def _resolve_radio(self, master_radio):
active = next((
radio for radio in
master_radio.get_group()
if radio.get_active()
))
return active
This uses a generator to return the first (which should be the only) active radio box that is active.
This is how I do it.
GtkRadioButton * radio_button;
GtkRadioButton * radio_button1;
GtkRadioButton * radio_button2;
...
GSList * tmp_list = gtk_radio_button_get_group (radio_button);//Get the group of them.
GtkToggleButton *tmp_button = NULL;//Create a temp toggle button.
while (tmp_list)//As long as we didn't reach the end of the group.
{
tmp_button = tmp_list->data;//Get one of the buttons in the group.
tmp_list = tmp_list->next;//Next time we're going to check this one.
if (gtk_toggle_button_get_active(tmp_button))//Is this the one active?
break;//Yes.
tmp_button = NULL;//We've enumerated all of them, and none of them is active.
}
//Here. tmp_button holds the active one. NULL if none of them is active.
See the discussion here.
I don't know if they will add this function into it (seems not).
Here's how I suggest doing it:
void radio_button_selected (GtkWidget *widget, gpointer data)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))
{
GSLIST *group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
g_print ("Index = %i%\n", g_slist_index (group, widget));
}
}
You may connect to the GtkToggleButton::toggled signal instead. In the associated callback, you'll be able to update your variable. As for the call to gtk_radio_button_get_group, you only need it if you call gtk_radio_button_new_with_label instead of gtk_radio_button_new_with_label_with_widget, as specified in the tutorial you're refering to.
Let's create a serie of buttons :
for severity in levels:
radio = gtk.RadioButton(group=radioButtons, label=severity)
if severity == actualLevel:
radio.set_active(True)
hBox.pack_start(radio, True, True, 3)
radio.connect('toggled', self.radioButtonSelected, severity)
and all buttons are connected to the same handler :
def radioButtonSelected(self, button, currentSeverity):
# proceed with the task
# as you can see, button is passed by as argument by the event handler
# and you can, for example, get the button label :
labelReadFromButton = button.getLabel()
Use lambda expressions if you dont want to mess around with the annoying methods, still have to use connect though, but its alot easier to read:
Enum RadioValues { A, B, C, none };
RadioValues values = RadioValues.none; // only needed if you dont have an initially selected radio button
MyConstructor()
{
Build();
// asumming you have 3 radio buttons: radioA, radioB, radioC:
radioA.Toggled += (sender,e) => values = RadioValues.A;
radioB.Toggled += (sender,e) => values = RadioValues.B;
radioC.Toggled += (sender,e) => values = RadioValues.C;
}
and thats it, no methods to deal with, and you dont have to restrict yourself to just that either, you can also use an anonymous function if you need more flex--of course the next step after that is using methods. Unfortunately they didnt offer a simple .Checked property, my next suggestion is to override the radio button itself and chain a Checked property when it's toggled state is changed, emulating other frameworks like MFC, Qt, and Winforms... etc.
PS: I left out boilerplate code for simplicity's sake, which can make answers a bit more muddled and you probably just want the facts not a demonstration on whether or not I can properly call a constructor :)
My solution for GTKmm is quite easier,
You just have to call the function :
my_radio_button.get_active(); \n
This will return either 0 if its unactive or 1 if its active.
This is a demo code using Radio Buttons, where you can find how I find which radio button is selected:
#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <gtkmm/radiobutton.h>
#include <gtkmm/separator.h>
#include <gtkmm/application.h>
#include <iostream>
class ButtonWindow : public Gtk::Window
{
private:
//Child widgets:
Gtk::Box m_Box_Top, m_Box1, m_Box2;
Gtk::RadioButton m_RadioButton1, m_RadioButton2, m_RadioButton3;
Gtk::Separator m_Separator;
Gtk::Button m_Button_Close;
Gtk::RadioButton *m_SelectedButton{nullptr};
public:
ButtonWindow()
: m_Box_Top(Gtk::ORIENTATION_VERTICAL),
m_Box1(Gtk::ORIENTATION_VERTICAL, 15),
m_Box2(Gtk::ORIENTATION_VERTICAL, 0),
m_RadioButton1("button 1"),
m_RadioButton2("button 2"),
m_RadioButton3("button 3"),
m_Button_Close("close")
{
// Set title and border of the window
set_title("radio buttons");
set_border_width(0);
// Put radio buttons 2 and 3 in the same group as 1:
m_RadioButton2.join_group(m_RadioButton1);
m_RadioButton3.join_group(m_RadioButton1);
// Add outer box to the window (because the window
// can only contain a single widget)
add(m_Box_Top);
//Put the inner boxes and the separator in the outer box:
m_Box_Top.pack_start(m_Box1);
m_Box_Top.pack_start(m_Separator);
m_Box_Top.pack_start(m_Box2);
// Set the inner boxes' borders
m_Box1.set_border_width(20);
m_Box2.set_border_width(10);
// Put the radio buttons in Box1:
m_Box1.pack_start(m_RadioButton1);
m_Box1.pack_start(m_RadioButton2);
m_Box1.pack_start(m_RadioButton3);
// Put Close button in Box2:
m_Box2.pack_start(m_Button_Close);
// Connect the button signals:
#if 1 // Full C++11: (change this to #if 0 to use the traditional way)
m_RadioButton1.signal_clicked().connect([&]{on_radio_button_clicked(m_RadioButton1);});
m_RadioButton2.signal_clicked().connect([&]{on_radio_button_clicked(m_RadioButton2);});
m_RadioButton3.signal_clicked().connect([&]{on_radio_button_clicked(m_RadioButton3);});
m_Button_Close.signal_clicked().connect([&]{on_close_button_clicked();});
#else // Traditional:
m_RadioButton1.signal_clicked() // Full sigc
.connect(sigc::bind(sigc::mem_fun(*this, &ButtonWindow::on_radio_button_clicked),
sigc::ref(m_RadioButton1)));
m_RadioButton2.signal_clicked() // sigc && C++98
.connect(std::bind(sigc::mem_fun(*this, &ButtonWindow::on_radio_button_clicked),
std::ref(m_RadioButton2)));
m_RadioButton3.signal_clicked() // Full C++98
.connect(std::bind(&ButtonWindow::on_radio_button_clicked, this,
std::ref(m_RadioButton3)));
m_Button_Close.signal_clicked()
.connect(sigc::mem_fun(*this, &ButtonWindow::on_close_button_clicked));
#endif
// Set the second button active:
m_RadioButton2.set_active();
// Make the close button the default widget:
m_Button_Close.set_can_default();
m_Button_Close.grab_default();
// Show all children of the window:
show_all_children();
}
protected:
//Signal handlers:
void on_radio_button_clicked(Gtk::RadioButton& button)
{
if(m_SelectedButton != &button && button.get_active())
{
m_SelectedButton = &button;
std::cout << "Radio "<< m_SelectedButton->get_label() << " selected.\n";
}
}
void on_close_button_clicked()
{
hide(); // Close the application
}
};
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
ButtonWindow button;
//Shows the window and returns when it is closed.
return app->run(button);
}

GWT CellBrowser- how to always show all values?

GWT's CellBrowser is a great way of presenting dynamic data.
However when the browser contains more rows than some (seemingly) arbitrary maximum, it offers a "Show More" label that the user can click to fetch the unseen rows.
How can I disable this behavior, and force it to always show every row?
There are several ways of getting rid of the "Show More" (which you can combine):
In your TreeViewModel, in your NodeInfo's setDisplay or in the DataProvider your give to the DefaultNodeInfo, in onRangeChange: overwrite the display's visible range to the size of your data.
Extend CellBrowser and override its createPager method to return null. It won't change the list's page size though, but you can set it to some very high value there too.
The below CellBrowser removes the "Show More" text plus loads all available elements without paging.
public class ShowAllElementsCellBrowser extends CellBrowser {
public ShowAllElementsCellBrowser(TreeViewModel viewModel, CellBrowser.Resources resources) {
super(viewModel, null, resources);
}
#Override
protected <C> Widget createPager(HasData<C> display) {
PageSizePager pager = new PageSizePager(Integer.MAX_VALUE);
// removes the text "Show More" during loading
display.setRowCount(0);
// increase the visible range so that no one ever needs to page
display.setVisibleRange(0, Integer.MAX_VALUE);
pager.setDisplay(display);
return pager;
}
}
I found a valid and simple solution in setting page size to the CellBrowser's builder.
Hope this will help.
CellBrowser.Builder<AClass> cellBuilder = new CellBrowser.Builder<AClass>(myModel, null);
cellBuilder.pageSize(Integer.MAX_VALUE);
cellBrowser = cellBuilder.build();
The easiest way to do this is by using the:
cellTree.setDefaultNodeSize(Integer.MAX_VALUE);
method on your Cell Tree. You must do this before you begin expanding the tree.
My workaround is to navigate through elements of treeview dom to get "show more" element with
public static List<Element> findElements(Element element) {
ArrayList<Element> result = new ArrayList<Element>();
findShowMore(result, element); return result; }
private static void findShowMore(ArrayList res, Element element) {
String c;
if (element == null) { return; }
if (element.getInnerText().equals("Show more")) { res.add(element);
}
for (int i = 0; i < DOM.getChildCount(element); i++) { Element
child = DOM.getChild(element, i); findShowMore(res, child); } }
and than use:
if (show) { element.getStyle().clearDisplay(); } else {
element.getStyle().setDisplay(Display.NONE); }