小编boo*_*y99的帖子

如何在onclick期间切换片段?

我有一个我想做的项目.我遇到了一个小问题,我不知道如何绕过它.下面是目前为止的应用程序的图像.

我想要它做的是当用户点击其中一个列表项时,显示"Hello!It's Fragment2"的部分更改为我在应用程序中声明的新xml.因此,如果我单击ATO listItem,那么右侧的片段应该更改为"Hello!It's ATO Fragment"

在此输入图像描述

到目前为止,这是我的代码:

AndroidListFragmentActivity:

package com.exercise.AndroidListFragment;

import android.app.Activity;
import android.os.Bundle;

public class AndroidListFragmentActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
Run Code Online (Sandbox Code Playgroud)

Fragment2:

package com.exercise.AndroidListFragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment2 extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.fragment2, container, false);
    }

}  
Run Code Online (Sandbox Code Playgroud)

MyListFragment1: …

android android-fragments

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

找到最近的纬度和经度

我正在编写一个小程序并提高效率,我需要能够在我的数组中找到最接近的纬度和经度.

假设您有以下代码:

tempDataList = [{'lat': 39.7612992 , 'lon': -86.1519681}, 
                {"lat": 39.762241, "lon": -86.158436}, 
                {"lat": 39.7622292, "lon": -86.1578917}]

tempLatList = []
tempLonList = []

for item in tempDataList:
    tempLatList.append(item['lat'])
    tempLonList.append(item['lon'])

closestLatValue = lambda myvalue: min(tempLatList, key=lambda x: abs(x - myvalue))
closestLonValue = lambda myvalue: min(tempLonList, key=lambda x: abs(x - myvalue))

print(closestLatValue(39.7622290), closestLonValue(-86.1519750))
Run Code Online (Sandbox Code Playgroud)

我得到的结果是:

(39.7622292, -86.1519681)
Run Code Online (Sandbox Code Playgroud)

应该是什么(在这个例子中,列表中的最后一个对象)

(39.7622292, -86.1578917)
Run Code Online (Sandbox Code Playgroud)

我知道如何获得单个值的最接近的单元格,但是,我想让lambda函数考虑这两个值,但我不完全确定如何.救命?

python

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

从Google App Engine调用Firebase数据库

我按照本教程设置了我的Google App Engine实例,我也在使用Firebase.我的目标是将所有"计算"放在Google App Engine上.我想调用下面这样的函数:

MyEndpoint:

package productions.widowmaker110.backend;

/** An endpoint class we are exposing */
@Api(
 name = "myApi",
 version = "v1",
 namespace = @ApiNamespace(
 ownerDomain = "backend.widowmaker110.productions",
 ownerName = "backend.widowmaker110.productions",
 packagePath=""
 )
)
public class MyEndpoint {

 /** A simple endpoint method that takes a name and says Hi back */
 @ApiMethod(name = "sayHi")
 public MyBean sayHi(@Named("name") String name) {

 // Write a message to the database
 FirebaseDatabase database = FirebaseDatabase.getInstance();
 DatabaseReference myRef = database.getReference("message");

 // …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine android firebase

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

针对大数的高效Prime分解

我一直在研究一个小问题,我需要将18位数字计算到它们各自的素数分解中.考虑到它确实有效,所有的东西都会编译并运行得很好,但我希望减少素数分解的运行时间.我已经实现了递归和线程,但我想我可能需要一些帮助来理解大数计算的可能算法.

每次我在预制的4个数字上运行时,大约需要10秒钟.如果有任何想法,我想减少到0.06秒.

我注意到了一些像Eratosthenes筛选的算法,并在计算之前生成了所有素数的列表.我只是想知道是否有人可以详细说明.例如,我在理解如何将Eratosthenes的Sieve实现到我的程序中或者它是否是一个好主意时遇到了问题.关于如何更好地接近这一点的任何和所有指针都会非常有用!

这是我的代码:

#include <iostream>
#include <thread>
#include <vector>
#include <chrono>

using namespace std;
using namespace std::chrono;

vector<thread> threads;
vector<long long> inputVector;
bool developer = false; 
vector<unsigned long long> factor_base;
vector<long long> primeVector;

class PrimeNumber
{
    long long initValue;        // the number being prime factored
    vector<long long> factors;  // all of the factor values
public:
    void setInitValue(long long n)
    {
        initValue = n;
    }
    void addToVector(long long m)
    {
        factors.push_back(m);
    }
    void setVector(vector<long long> m) …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm primes multithreading prime-factoring

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

打印向量内容时出现 ConcurrentModificationException

好吧,我想编写一个程序,允许用户输入无限数量的数字,然后再次以相同的顺序打印它们。

我收到此错误:

Exception in thread "main" java.util.ConcurrentModificationException
    at java.util.Vector$Itr.checkForComodification(Unknown Source)
    at java.util.Vector$Itr.next(Unknown Source)
    at myPackage.Main.main(Main.java:41)
Run Code Online (Sandbox Code Playgroud)

第 41 行是这一行“System.out.println(itr.next());” 一

这是我的代码:

package myPackage;

import java.util.Scanner;
import java.util.Vector;
import java.lang.Integer;
import java.util.Iterator;

public class Main {

private static Scanner user_input;

public static void main(String[] args) {

    int first = 42;
    int second = 84;

    user_input = new Scanner(System.in);

    Vector<Integer> v = new Vector<Integer>();

    Iterator<Integer> itr = v.iterator();

    System.out.println("Please enter the numbers you wish to store temporarily before printing. When finished, enter either …
Run Code Online (Sandbox Code Playgroud)

java concurrentmodification

3
推荐指数
1
解决办法
2916
查看次数

JQuery Table row .on("click" 查找是否单击了超链接或只是单击了行

我正在开发一个包含以下库的网站:

  • 解析.js:1.4.2
  • JQuery:1.11.2 和 1.10.3(用户界面)
  • Twitter 引导程序:3.3.4

我用虚拟数据创建了这个 JSfiddle 来解释我正在寻找的内容:https ://jsfiddle.net/xuf7wy4x/1/

截至目前,如果我单击该行上的任何位置,则会触发 onclick 侦听器,但不会区分超链接。每当我单击行中的电子邮件超链接时,底部的对话框就会打开,并且默认的邮件程序(例如 Outlook)会同时打开,这很烦人。我想说的是“如果 onclick 捕获超链接,则不要打开对话框。否则,如果 onclick 中没有触及超链接,则打开对话框”。

我不知道如何区分一般点击和指向超链接的点击。非常感谢任何帮助!

以防万一,代码是:

超文本标记语言

<div class="container">
                <div class="row">
                    </div>
                    <div class="col-xs-6 table-responsive peoplelist" id="peoplelist">
                    <h3>People within the bowl  <small><i>Hint:</i> click on the rows to edit or delete them</small></h3>
                        <table class="table table-striped table-hover bowlsetting">
                            <thead>
                                <tr>
                                    <th>First Name</th>
                                    <th>Last Name</th>
                                    <th>Role</th>
                                    <th>Email</th>
                                    <th>School</th>
                                </tr>
                            </thead>
                            <tbody id="bowsettingsbody">
                                <tr class="bowsettingperson">
                            <td> firstName </td>
                            <td> lastName </td>
                            <td> role</td>
                            <td><a href="mailto:mystu@gmail.com?Subject=Ethics Bowl:&body=body" target="_top">mystu@gmail.com</a></td>
                            <td> …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery hyperlink twitter-bootstrap

3
推荐指数
1
解决办法
4040
查看次数

JQuery .on('click'...问题引用list-group-items

我正在写一个大型网站,我被卡住引用一个小导航栏.我正在使用Twitter Bootstrap.

我确定我错过了一些新手.这是JsFiddle:http://jsfiddle.net/ugdh2jmL/2/.我将引用一系列动态加载的列表对象.我可以很容易地添加它们,但我有问题声明onclick事件; 什么都没有,没有消息,没有.

以下是片段:

$('.list-group').on('click', '.list-group-item', function(e) {
  alert('success');
}):
Run Code Online (Sandbox Code Playgroud)
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div class="col-sm-4">
  <div class="container">
    <div class="row">
      <div class="col-sm-4">
        <div class="list-group">
          <a href="#" class="list-group-item active">
            <h4 class="list-group-item-heading">List group item heading</h4>
            <p class="list-group-item-text">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
          </a>
          <a href="#" class="list-group-item">
            <h4 class="list-group-item-heading">List group item heading</h4>
            <p class="list-group-item-text">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery twitter-bootstrap

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

动态设置Timepicker的小时和分钟

我正在向我的网页动态添加Timepickers。一旦我加载了所有的 html,或者基本上做了jquery.append()

<div class="input-group bootstrap-timepicker" style="padding-bottom:10px;">
   <input class="form-control timepicker"id="timepicker-default" type="text">
        <span class="input-group-addon">
           <i class="fa fa-clock-o"></i>
        </span>
    </input>
</div>
Run Code Online (Sandbox Code Playgroud)

进而:

$('.timepicker').each(function(){
    $(this).timepicker();
}); 
Run Code Online (Sandbox Code Playgroud)

将它们绑定到我网站中的 timepicker.js 文件。

我的问题是我希望能够在执行上述 for-each 函数时设置时间。我正在使用Parse.com作为我的后端,因此日期显示为“2015 年 9 月 1 日星期二 13:15:00 GMT-0400(东部夏令时间)”。我希望能够从我刚刚提到的时间中提取时间,然后设置当前打开的时间选择器的小时和分钟。我知道循环遍历每一个的逻辑,但我不知道如何设置单个时间选择器。

我试图在jsfiddle 中为您运行一个示例,但无法正确加载它。

PS 我知道 for-each 函数正在工作,因为我已经对其进行了测试。

html javascript jquery timepicker

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

如何比较char或string变量是否等于某个字符串?

我试图让这个循环工作,但由于某种原因,它会自动"假设"用户输入错误.

value是一个字符串(它应该是一个字符?) , ,A 是字符串(他们应该是char?)BC

void Course::set()
{
    cout << "blah blah blah" << endl;
    cout << "youre options are A, B, C" <<endl;
    cin >> value;

    while(Comp != "A" || Comp != "B" || Comp != "C") 
    {
        cout << "The character you enter is not correct, please enter one of the following: You're options are A, B, C" << endl;
        cin >> value;
    }
    cout << endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ comparison string-comparison logical-operators

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