我知道有这个文档
http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog
但作为一个新的Android/Java学习者,通过编写一个弹出2个选项(是/否)消息的简单警告对话框来理解所涉及的代码量并不容易.
这是我目前在MainActivity文件中的代码:
final private int RESET_DIALOG = 0;
private OnClickListener resetButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(RESET_DIALOG);
}
};
protected android.app.Dialog onCreateDialog(int id) {
switch(id) {
case RESET_DIALOG:
AlertDialog.Builder builder = new Builder(this);
return builder
.setMessage("Are you sure you want to reset the count?")
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(MainActivity.this, "Did not reset!", 5).show();
}
})
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int …Run Code Online (Sandbox Code Playgroud) 我正在使用我的json对象返回一个结果数组,我正在尝试使用我的customObjectResponse类来拉出每个对象中的每个字段...它期望一个对象的问题所以我如何编辑我的类允许它接受一个对象数组,然后可以调用每个对象的字段...我很困惑,需要添加什么:
以下是要传递的内容的响应示例:
[
{
itemId: 'dfsdfsdf343434',
name: 'tests',
picture: '6976-7jv8h5.jpg',
description: 'testy.',
dateUpdated: 1395101819,
}
]
Run Code Online (Sandbox Code Playgroud)
这是我的响应对象类:
public class ObjResponse{
private String itemId;
private String name;
private String picture;
private String description;
private String location;
private int dateUpdated;
private String msg;
//gridview constructor
public ObjResponse(String picture) {
this.picture = picture;
}
//public constructor
public ObjResponse() {
}
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getName() {
return name;
} …Run Code Online (Sandbox Code Playgroud) 嘿我正在尝试从node.js导出csv(从mongodb中提取数据).我已经将数据拉动并用逗号分隔所有,但现在我想弄清楚如何实际发送它......我将这段代码粘贴在我的路径文件中.有关如何获取数据并将其发送给用户直接下载的任何建议.
这里是代码:(我尝试了代码底部的第二个功能)
exports.downloadContacts = function(req, res) {
async.waterfall([
function(callback) {
var source = [];
Friend.find({userId: req.signedCookies.userid}, function(err, friends) {
if(err) {console.log('err with friends for download');
} else {
var userMap = {};
var friendIds = friends.map(function (user) {
userMap[user.friend_id] = user;
return user.friend_id;
});
console.log(friends);
User.find({_id: {$in: friendIds}}, function(err, users) {
if(err) {console.log(err);
} else {
for(var i = 0; i < users.length; i++) {
console.log('users')
//console.log(users[i]);
source.push(users[i].firstNameTrue, users[i].lastNameTrue, users[i].emailTrue, users[i].phone, users[i].emailList, users[i].phoneList)
}
console.log(source);
callback(null, source);
}
});
} …Run Code Online (Sandbox Code Playgroud) 我试图找出一种有效的方法来从数组中删除重复的对象,并寻找最有效的答案.我环顾互联网,一切似乎都在使用原始数据...或者不能扩展到大型数组.这是我目前的实现,可以改进,并希望尝试避免标签.
Test.prototype.unique = function (arr, artist, title, cb) {
console.log(arr.length);
var n, y, x, i, r;
r = [];
o: for (i = 0, n = arr.length; i < n; i++) {
for (x = 0, y = r.length; x < y; x++) {
if (r[x].artist == arr[i].artist && r[x].title == arr[i].title) {
continue o;
}
}
r.push(arr[i]);
}
cb(r);
};
Run Code Online (Sandbox Code Playgroud)
并且数组看起来像这样:
[{title: sky, artist: jon}, {title: rain, artist: Paul}, ....]
Run Code Online (Sandbox Code Playgroud)
订单无关紧要,但如果排序使其更有效率,那么我就迎接挑战......
并且对于那些不知道o的人来说是一个标签,它只是说跳回循环而不是推送到新阵列.
纯javascript请没有库.
回答如此:
以下答案的性能测试:http: //jsperf.com/remove-duplicates-for-loops
嘿我不确定为什么每次我在画廊中选择图像时都会出现这种情况?
这是代码:
if (v == uploadImageButton) {
// below allows you to open the phones gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Complete action using"), 1);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == 1 && null != data) {
// Bitmap photo = (Bitmap) data.getData().getPath();
Uri selectedImageUri = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImageUri,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = …Run Code Online (Sandbox Code Playgroud) 我读到了请求拦截器以及什么不是但不知道如何真正使用它们来获取cookie ...我从nodejs发送这样的cookie ...
res.cookie('userid', user._id, { maxAge: 86400000, signed: true, path: '/' });
Run Code Online (Sandbox Code Playgroud)
在我的Android客户端 - 我为RestApiManager设置了这个
public class RestApiManager {
private static final String API_URL = "ip: port";
private static final RestAdapter REST_ADAPTER = new RestAdapter.Builder()
.setEndpoint(API_URL)
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
//Call interface
public interface AsynchronousApi {
//Login User
@FormUrlEncoded
@POST("/login")
public void loginUser(
@Field("loginName") String loginName,
@Field("password") String password,
Callback<UserResponse> callback);
//Profile Picture
@Multipart
@POST("/profilePicture")
public void uploadProfilePicture(
@Part("photo") TypedFile photo,
@Part("userId") String userId,
Callback<UserResponse> callback); //success thumbnail to picasso
} …Run Code Online (Sandbox Code Playgroud) 当键盘显示时,我无法向上推整个回收器视图,它切断了之前的消息。我正在创建一个看起来像这个 xml 的聊天视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/commentsParentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/noCommentsResults"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lineSep"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/noCommentsFound"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/pullToLoadMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lineSep"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:paddingBottom="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/comments_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<View
android:id="@+id/lineSep"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@+id/commentsAddLayout"
android:background="@color/horizontalLine" />
<LinearLayout
android:id="@+id/commentsAddLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/emojiSelector"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="1"
android:src="@drawable/emoji" />
<EditText
android:id="@+id/commentText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="4"
android:background="@android:color/transparent"
android:hint="@string/add_comment"
android:maxLength="150" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/horizontalLine" />
<TextView …Run Code Online (Sandbox Code Playgroud) 我不知道为什么它出现为null,如果它必须对片段和片段标题或抽屉做一些事情,因为它是在这个片段被拉出的主要活动上.
这是我的菜单xml项目:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
Run Code Online (Sandbox Code Playgroud)
这是片段代码:
public class BrowseFragment extends Fragment {
//action bar expands to search
//search - keyword or tab search, title
//include popular - same algorithm as home
//show categories
//category click takes you to grid activity
//adapter with custom model
private CategoryViewerAdapter adapter;
//list with custom model
private List<CategoryItem> categoriesList;
//List view
private ListView categoryListView;
//SearchView
private SearchView search;
@Override
public void onCreateOptionsMenu(Menu menu, …Run Code Online (Sandbox Code Playgroud) 我很难让 cookie 工作,在服务器端,我使用它们通过从 req.cookies 中获取它们来验证用户。
这是我目前在 React Native 中的 Login.js 文件中设置它的方式:
import Cookies from "universal-cookie";
const cookies = new Cookies();
cookies.set("token", token, {
expires: 7, // 7 days
path: "/"
//,secure: true // If served over HTTPS
});
Run Code Online (Sandbox Code Playgroud)
当我cookies.get("token")在此页面上调用 a 时,这工作正常。但是,当我导入、设置常量并在另一个页面上调用 get 时,令牌没有显示......
另外,当我像这样进行提取时:
fetch("http://192.168.0.115:3000/myTransactions/", {
credentials: "same-origin",
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
})
Run Code Online (Sandbox Code Playgroud)
服务器不会收到任何 cookie。我什至更改了凭据以说包含。
我在 Windows 上使用 expo 和我的终端来运行它,而无需使用 android studio 或 xcode。我不确定这是否是一个可能的问题。
有什么想法吗!
谢谢
单击注销按钮时,我很难删除 cookie。我目前有一个带有类注销的注销按钮。这是我试图删除cookie的简单jquery行,但它不起作用。
$('button .logout').click(function () {
$.cookie('userid', null);
};
Run Code Online (Sandbox Code Playgroud)
userid 是 cookie 的名称。
哦,我正在使用签名 cookie,不确定这是否会改变什么?
编辑:
这是我设置cookie的方法:
exports.loginPost = function(req, res, next) {
console.log("here 1");
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err) }
if (!user) {
return res.render('loginError', {title: 'Weblio'}); }
req.logIn(user, function(err) {
if (err) { return next(err); }
console.log(JSON.stringify(user));
res.cookie('userid', user._id, { maxAge: 900000, signed: true });
res.redirect('userProfile');
});
})(req, res, next);
};
Run Code Online (Sandbox Code Playgroud)
并使用一个简单的 express - node js cookieParser,其中包含一个秘密。