我正在尝试使用picasso库来加载url到imageView,但我无法context
正确使用picasso库.
public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
private List<Post> mDataset;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView txtHeader;
public ImageView pub_image;
public ViewHolder(View v) {
super(v); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JSON正文发出HTTP post请求:
如何能够将NSdictionnary添加到HTTP请求主体.
这是我的代码,它似乎无法正常工作.
var entry1 = Response(IdQuestion: 6510,IdProposition: 10,Time: 30)
var entry2 = Response(IdQuestion: 8284,IdProposition: 10,Time: 30)
Responses.append(entry1)
Responses.append(entry2)
let list = Responses.map { $0.asDictionary }
let json = ["List":list,"IdSurvey":"102","IdUser":"iOSclient","UserInformation":"iOSClient"]
let data : NSData = NSKeyedArchiver.archivedDataWithRootObject(json)
NSJSONSerialization.isValidJSONObject(json)
let myURL = NSURL(string: "http://www.myserver.com")!
let request = NSMutableURLRequest(URL: myURL)
request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.HTTPBody = data
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
println(response)
// Your completion handler code here
}
task.resume()
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Alamofire快速发布一个关于身体的帖子请求.
我的json身体看起来像:
{
"IdQuiz" : 102,
"IdUser" : "iosclient",
"User" : "iosclient",
"List":[
{
"IdQuestion" : 5,
"IdProposition": 2,
"Time" : 32
},
{
"IdQuestion" : 4,
"IdProposition": 3,
"Time" : 9
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试let
list
使用NSDictionnary,它看起来像:
[[Time: 30, IdQuestion: 6510, idProposition: 10], [Time: 30, IdQuestion: 8284, idProposition: 10]]
Run Code Online (Sandbox Code Playgroud)
我使用Alamofire的请求看起来像:
Alamofire.request(.POST, "http://myserver.com", parameters: ["IdQuiz":"102","IdUser":"iOSclient","User":"iOSClient","List":list ], encoding: .JSON)
.response { request, response, data, error in
let dataString = NSString(data: data!, encoding:NSUTF8StringEncoding)
println(dataString)
}
Run Code Online (Sandbox Code Playgroud)
请求有一个错误,我相信问题是在字典列表,因为如果我提出一个没有列表的请求它工作正常,所以任何想法?
我尝试过建议的解决方案,但我遇到了同样的问题:
let json = ["List":list,"IdQuiz":"102","IdUser":"iOSclient","UserInformation":"iOSClient"] …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在RecyclerView中加载Youtube视频缩略图.我正面临一些问题.
这是我在适配器中正在做的事情:
public static class ItemViewHolder extends RecyclerView.ViewHolder {
private YouTubeThumbnailView thumb;
public Post post;
public ItemViewHolder(View v) {
thumb = (YouTubeThumbnailView) v.findViewById(R.id.youtube_thumbnail);
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof ItemViewHolder) {
((ItemViewHolder) holder).thumb.initialize(YOUTUPEKEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader youTubeThumbnailLoader) {
youTubeThumbnailLoader.setVideo(VIDEOID);
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
}});
}}}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我不是我做得对.当我在另一个活动中使用相同的适配器时,我收到此错误:
Activity com.example.yasser.version6.Mespublications has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@4252bcb8 that was originally bound here
Run Code Online (Sandbox Code Playgroud)
加载缩略图需要时间,有时在滑动时会在它们之间混合.
我添加了一个函数来释放所有Youtube加载器:
public void …
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助,如何使用Javascript或jQuery或任何库(如果可用)检查互联网连接.因为我正在开发一个离线应用程序,我希望在用户离线时显示一个版本,如果用户在线则显示另一个版本.
目前我正在使用此代码:
if (navigator.onLine) {
alert('online');
} else {
alert('offline');
}
Run Code Online (Sandbox Code Playgroud)
但这种方法检测起来很慢.有时它只是连接到没有互联网的网络,需要5到10秒才能发出警报false
(没有互联网).
我看了一下Offline.js库,但我不确定这个库在我的情况下是否有用.我不知道如何使用它
我希望能够在CollapsingToolbarLayout内滚动ImageView.那么怎么可能,以及如何设置该图像视图的起始高度?
我的ImageView高度为280p,在活动开始时我要显示200p然后我可以向下滚动以查看图像的其余部分.我在WhatsApp应用程序中看到了类似的东西.
这是一个链接,看看我想要什么:
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.yasser.version6.Profile">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:fitsSystemWindows="true"
android:layout_height="@dimen/app_bar_height"
android:layout_width="match_parent"
android:theme="@style/MyMaterialTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/tof" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="@style/MyMaterialTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/content"
layout="@layout/content_profile" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
内容简介代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
tools:showIn="@layout/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.yasser.version6.Profile">
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud) android android-design-library android-collapsingtoolbarlayout
我正在使用一个名为exec-php的Node包来在Node.js应用程序中执行PHP函数.
我想将该应用程序推送到Heroku,但我想知道如何制作它,以及如何在本地PHP包中.
我正在使用/Applications/MAMP/bin/php/php7.0.0/bin/php
.在Heroku中,PHP bin的路径是什么?
我测试了vendor/bin/heroku-php-apache2,但它不起作用,那么Heroku中的PHP二进制文件的路径是什么?
我正在使用presentViewController从一个视图更改为另一个没有导航控制器,如:
let HomeView = self.storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! ViewControllerHome
self.presentViewController(HomeView, animated:true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
如何改变过渡?我想像导航控制器一样动画.
我可以使用另一个转换,但我发现我想要的转换是我正在使用的代码
let HomeView = self.storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! ViewControllerHome
HomeView.modalTransitionStyle = UIModalTransitionStyle.PartialCurl
self.presentViewController(HomeView, animated:true, completion: nil)
Run Code Online (Sandbox Code Playgroud) 我正在尝试在活动布局的底部添加另一个操作栏或菜单,并保留顶部操作栏.
像这样的东西:
这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.yasser.version6.PublierActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:id="@+id/user"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_margin="4dp"
android:id="@+id/profil_image"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="218dp"
android:layout_marginEnd="218dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences"
android:ems="10"
android:background="#00000000"
android:layout_margin="4dp"
android:hint="Écriver quelque chose..."
android:id="@+id/publication_text"
android:maxLength="150"
android:textSize="15dp"
android:maxLines="3"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<requestFocus />
</EditText>
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="@dimen/image_size"
android:id="@+id/publication_image"
android:layout_weight="1"
android:padding="0dp"
android:background="@drawable/default_image"
android:layout_marginTop="5dp"
android:scaleType="fitXY"
android:layout_below="@+id/user" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我试图添加一个自定义RelativeLayout,看起来几乎像一个操作栏,但工具栏上升,搞砸了一切.