Retrofit 2
我目前正在使用,我想在我的服务器上传一些照片.我知道,旧版本使用TypedFile
类进行上传.如果我们想要使用进度条,我们应该writeTo
在TypedFile
类中重写方法.
使用retrofit 2
库时是否可以显示进度?
我想用水平图库创建应用程序(有一行和多列).首先我尝试使用gridview,但它只能用作垂直滚动.我可以使用ListView
或GridView
用于此目的吗?
我将Retrofit
库版本 2 与OkHttpClient
.
我想从所有响应中获取一些标题。
我找到了一种解决方案OkClient
:
public class InterceptingOkClient extends OkClient{
public InterceptingOkClient()
{
}
public InterceptingOkClient(OkHttpClient client)
{
super(client);
}
@Override
public Response execute(Request request) throws IOException
{
Response response = super.execute(request);
for (Header header : response.getHeaders())
{
// do something with header
}
return response;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我正在使用,我该怎么做OkHttpClient
?
Fragment
我Activity
像这样向我添加一个:
getSupportFragmentManager()
.beginTransaction()
.add(R.id.frame_container, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(fragment.getClass().getName())
.commit();
Run Code Online (Sandbox Code Playgroud)
但是当我想找到Fragment
使用时,FragmentManager
它返回null:
Fragment oldFragment = (Fragment) getSupportFragmentManager().findFragmentByTag(fragment.getClass().getName());
Run Code Online (Sandbox Code Playgroud) 我正在使用GCM Cloud Listener Service从我的服务器捕获一些通知并通过状态栏显示它 NotificationCompat
出于某种原因,如果我的片段(包含一些可更新项目的列表)现在显示,我不会显示我的通知.
检查的最佳方法是从现在可见的片段CloudListenerService
?
我想我可以Application
用于存储片段的当前状态:
在应用程序类中:
public class ClientApplication extends Application {
public static WeakReference<Fragment> currentFragment;
Run Code Online (Sandbox Code Playgroud)
在我的Fragment
:
@Override
public void onResume() {
ClientApplication.fragment = new WeakReference<>(this);
super.onResume();
}
@Override
public void onPause() {
ClientApplication.fragment = null;
super.onPause();
}
Run Code Online (Sandbox Code Playgroud)
在我的Cloud listener service
:
if(ClientApplication.fragment.get() != null && ClientApplication.fragment.get().isVisible()) {
dosth();
Run Code Online (Sandbox Code Playgroud) android android-service android-fragments google-cloud-messaging
mGroupLayout.setOrientation(HORIZONTAL);
mGroupLayout.setWeightSum(2f);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0,
LinearLayout.LayoutParams.WRAP_CONTENT
);
params.weight = 1.0f;
leftLayout = new LinearLayout(getContext());
leftLayout.setOrientation(VERTICAL);
leftLayout.setLayoutParams(params);
mGroupLayout.addView(
leftLayout,
params
);
rightLayout = new LinearLayout(getContext());
rightLayout.setOrientation(VERTICAL);
rightLayout.setLayoutParams(params);
mGroupLayout.addView(
rightLayout,
params
);
Run Code Online (Sandbox Code Playgroud)
但是我所有的线性布局都不可见(它们的宽度为 0)。我怎么能这样做?