小编Nat*_*Ngs的帖子

使用putExtra将值传递给intent服务

在我的主要活动中,我有以下代码:

EditText usernameText;
EditText passwordText;
public void sendLogin (View loginview){
    Intent i = new Intent(this, NetworkService.class);
    startService(i);
}
Run Code Online (Sandbox Code Playgroud)

目前,这只是向NetworkService发送一个intent,它按如下方式处理(截断):

public class NetworkService extends IntentService {

    public NetworkService() {
        super("NetworkService");
    }

    protected void onHandleIntent(Intent i) {

        /* HTTP CONNECTION STUFF */

        String login = URLEncoder.encode("Username", "UTF-8") + "=" + URLEncoder.encode("XXX", "UTF-8");
        login += "&" + URLEncoder.encode("Password", "UTF-8") + "=" + URLEncoder.encode("XXX", "UTF-8"); 
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,我需要弄清楚的是,如何将这些usernameTextpasswordText值传递到NetworkService'XXX'中,但是NetworkService我想打算(没有双关语),让它处理来自不同地方的多个意图,一个来自登录,例如,使用登录令牌检索用户的一些信息.这是我的所有网络都将被包含的地方.我被告知这是Android应用程序中的最佳实践,以保持网络分离.

我的问题是:什么是这两个变量发送到的最佳方式NetworkService,以及如何,内onHandleIntentNetworkService,我分开的代码只能做我要求它(登录,获取用户信息,获取位置数据等等)?

对不起,如果答案很简单,但我对应用程序编程很新. …

java android android-intent

18
推荐指数
2
解决办法
3万
查看次数

查看长时间运行的mongodb聚合作业的进度

我使用Mongodb(2.6.0-rc2)聚合框架进行了长时间的工作:http://docs.mongodb.org/manual/core/aggregation-introduction/

我已经在javascript中编写了聚合并将作业作为脚本运行
(即mongo localhost:27017/test myjsfile.js).
启动脚本后,有什么方法可以查看作业的进度吗?

例如,使用示例聚合作业:

db.zipcodes.aggregate([
    {$group: {
        _id: "$state",
        totalPop: {$sum: "$pop"}
    }},
    {$match: {totalPop: {$gte: 10*1000*1000 }}}
])
Run Code Online (Sandbox Code Playgroud)

我希望看到这份工作目前正在执行一个小组,并且完成了70%.

对于mongo的map reduce作业,您可以查看progress via db.currentOp(),其中有一个progress字段,显示完成的作业的百分比,如本文所述:

是否有可能在mongo中获取地图减少进度通知?

聚合有什么相似之处吗?

mongodb aggregation-framework

15
推荐指数
1
解决办法
2021
查看次数

FXML load()期间的JavaFX IllegalAccessException

我有一个由以下代码调用的对话框窗口(DialogController是一个使用模式对话框窗口的辅助类;它主要将控制器引用与其窗口捆绑在一起):

void handleServicesEdit(ActionEvent event) throws IOException {

    DCServRecEditor sre = DialogController.<DCServRecEditor>loadFXML(
            CensusAssistant.RES_FXML_DIALOG_SERVEDIT,
            CensusAssistant.RES_STRING_SERVEDIT,
            this.getDialog());
    sre.setDialogMode(DB.DBEDIT_MODE_EDIT,
                      tbvService.getItems(),
                      tbvService.getSelectionModel().getSelectedIndex(),
                      m_encCal);
    sre.showAndWait();

    sre.release();
    this.updateGUI();
}
Run Code Online (Sandbox Code Playgroud)

我已确认在该FXMLLoader.load()方法期间出现异常.我还确定错误发生在我的initialize()方法中的任何代码都有机会运行之前.我得到的一些堆栈跟踪load()在这里:

java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil 
    can not access a member of class org.kls.md.censusassistant.DCServRecEditor 
    with modifiers ""
file:/D:/Documents/NetBeansProjects/CensusAssistant/dist/run1284250063/CensusAssistant.jar!/org/kls/md/censusassistant/fxml/GUIServRecEditor.fxml:13
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:738)
  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:775)
  at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:180)
  at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:563)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
  at org.kls.md.censusassistant.DialogController.loadFXML(DialogController.java:63)
  at org.kls.md.censusassistant.DCMainEditor.handleServicesEdit(DCMainEditor.java:330)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        ...

Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil
    can not access a member of class …
Run Code Online (Sandbox Code Playgroud)

javafx javafx-2 illegalaccessexception fxml

13
推荐指数
1
解决办法
8641
查看次数

获取JavaFX中节点的高度(生成布局传递)

如何在JavaFX中获取节点的高度或者更喜欢高度,我有3 VBox并且我想将节点添加到最自由的面板,例如:

           Childrens      Total Height of the children's(Sum)
VBoxA          5                     890
VBoxB          4                     610
VBoxC          2                     720
Run Code Online (Sandbox Code Playgroud)

在这种情况下,最自由的是VBoxB,我用这种方法计算最自由的窗格:

private int getFreerColumnIndex() {
    if(columns.isEmpty())
        return -1;

    int columnIndex = 0;
    int minHeight = 0;
    for(int i = 0; i < columns.size(); i++) {
        int height = 0;
        for(Node n : columns.get(i).getChildren()) {
            height += n.getBoundsInLocal().getHeight();
        }

        if(i == 0) {
            minHeight = height;
        } else if(height < minHeight) {
            minHeight = height;
            columnIndex = i;
        }

        if(height == …
Run Code Online (Sandbox Code Playgroud)

java javafx vbox

12
推荐指数
1
解决办法
1万
查看次数

如何为JavaFX阶段创建调整大小动画?

我一直在尝试为JavaFX阶段进行缩放转换,以替换应用程序主窗口的当前场景(在本例中为登录框架).
当发生这种情况时,由于新场景较大,窗口会以非优雅的方式突然重新调整大小.

有没有办法设置一个缩放或重新调整大小的过渡来进行舞台大小调整?

相关代码:

InputStream is = null;
try {
    is = getClass().getResourceAsStream("/fxml/principal.fxml");
    Region pagina = (Region) cargadorFXML.load(is);
    cargadorFXML.<ContenedorPrincipal>getController().setEscenario(escenario);

    final Scene escena = new Scene(pagina, 900, 650);

    escena.setFill(Color.TRANSPARENT);
    escenario.setScene(escena);
    escenario.sizeToScene();
    escenario.centerOnScreen();
    escenario.show();
} catch (IOException ex) {
    // log "Unable to load the main application driver"
    log.error("No fue posible cargar el controlador principal de la aplicación."); 
    log.catching(ex);
} finally {
    if (is != null) {
        try {
            is.close();
        } catch (IOException e) {}
    }
}
Run Code Online (Sandbox Code Playgroud)

java javafx

11
推荐指数
2
解决办法
7620
查看次数

JavaFx可编辑组合框:在项目选择上显示toString

我有一个ComboBox<Perosn>类型Person,其中我添加了几个Person类的对象,

我已经使用setCellFactory(Callback)方法在ComboBox下拉列表中显示人名

combobox.setCellFactory(
    new Callback<ListView<Person >, ListCell<Person >>() {
        @Override
        public ListCell<Person > call(ListView<Person > p) {
            ListCell cell = new ListCell<Person >() {
                @Override
                protected void updateItem(Person item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        setText("");
                    } else {
                        setText(item.getName());
                    }
                }
            };
            return cell;
        }
    });
Run Code Online (Sandbox Code Playgroud)

并且,在选择上setButtonCell(ListCell)显示名称的方法combobox.

combobox.setButtonCell(
    new ListCell<Object>() {
        @Override
        protected void updateItem(Person t, boolean bln) {
            super.updateItem(t, bln); 
            if (bln) {
                setText(""); …
Run Code Online (Sandbox Code Playgroud)

combobox javafx javafx-2 javafx-8

10
推荐指数
2
解决办法
2万
查看次数

如何在JavaFX中禁用/隐藏工具提示

这就是我设置工具提示的方法:

if(Globals.isShowTooltips()) {
    locale = new Locale(Globals.getGuiLanguage());
    bundle = ResourceBundle.getBundle("bundles.lang", locale);            

    btnSettingsApply.setTooltip(
        new Tooltip(bundle.getString("btnSettingsApplyt")));

    btnSettingsOk.setTooltip(
        new Tooltip(bundle.getString("btnSettingsOkt")));

    btnSettingsCancel.setTooltip(
        new Tooltip(bundle.getString("btnSettingsCancelt")));            
}
Run Code Online (Sandbox Code Playgroud)

如何隐藏工具提示?在我看来,没有一个直截了当的方法.

任何帮助表示赞赏!

java javafx tooltip hide

8
推荐指数
1
解决办法
3315
查看次数

Android:事件ACTION_POWER_CONNECTED未发送到我的BroadcastReceiver

手机充电后我想做些什么.所以我创建了ChargingOnReciever:

public class ChargingOnReceiver extends BroadcastReceiver { 
    public void onReceive(Context context, Intent intent) { 
        context.startActivity(someActivity);
        Log.d(TAG, "Phone was connected to power");
    } 
} 
Run Code Online (Sandbox Code Playgroud)

我希望我的接收器听android.intent.action.ACTION_POWER_CONNECTED,所以我把它放到显而易见的地方:

<reciever android:name=".ChargingOnReceiver"
          android:enabled="true"
          android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
    </intent-filter>
</reciever>
Run Code Online (Sandbox Code Playgroud)

但是ChargingOnReceiver当我把G1放到充电器(通过USB线连接到我的笔记本电脑)时,显然没有启动.任何帮助深表感谢.

android android-intent

7
推荐指数
2
解决办法
1万
查看次数

在 golang 中将字符串转换为 *uint64

假设有一个字符串保存uint64类型变量的地址,我们可以将此地址解析回一个*uint64?

例如:

i := uint64(23473824)
ip := &i
str := fmt.Sprintf("%v", ip)

u, _ := strconv.ParseUint(str, 0, 64)
Run Code Online (Sandbox Code Playgroud)

uuint64。如何从这个值中取出指针?

游乐场链接:https : //play.golang.org/p/1KXFQcozRk

string pointers go uint64

7
推荐指数
2
解决办法
1万
查看次数

获取节点的维度 - JavaFX 2

我试图从Swing跳转到JavaFX.但我找不到如何获得节点的宽度和高度.

所以,这里有一些代码.

Label label = new Label();
label.setText("Hello");
label.setFont(new Font(32));

System.out.println(label.getPrefWidth());
System.out.println(label.getWidth());
System.out.println(label.getMinWidth());
System.out.println(label.getMaxWidth());
Run Code Online (Sandbox Code Playgroud)

结果是:

-1.0
 0.0
-1.0
-1.0
Run Code Online (Sandbox Code Playgroud)

Swing中的相同之处是:

JComponent.getPreferredSize().width
JComponent.getPreferredSize().height
Run Code Online (Sandbox Code Playgroud)

谢谢


编辑后:

为什么这不适合我?

public class Dimensions extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");

        primaryStage.setScene(new Scene(new MyPanel(), 500, 500));
        primaryStage.centerOnScreen();
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}
Run Code Online (Sandbox Code Playgroud)
public class MyPanel extends Pane {

    public MyPanel() {  
        Label label = new Label();
        label.setText("Hello");
        label.setFont(new Font(32));

        getChildren().add(label);

        label.relocate(150, 150);

        System.out.println(label.getWidth());
    }
}
Run Code Online (Sandbox Code Playgroud)

java javafx-2

6
推荐指数
2
解决办法
2万
查看次数