事实证明,这个社区对我的个人和学校项目非常有帮助,所以我决定加入。这是我的第一个问题。目前,我正在暑假空闲时间构建一个 Android 应用程序。我正在尝试在我的应用程序 fragment 之一中实现 SwipeRefreshLayout,但由于未知原因,当我拉动刷新时,我似乎无法让我的 fragment 调用 OnRefresh() 方法。
这是我的 Java 代码:
import android.app.Fragment;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Notifications extends Fragment implements OnRefreshListener{
private OnFragmentInteractionListener mListener;
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private SwipeRefreshLayout swipeLayout;
private View view;
public Notifications() {
}
public static Notifications newInstance() {
Notifications fragment = new Notifications();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
accessDataBase();
view = inflater.inflate(R.layout.fragment_notifications, container, false);
swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorSchemeColors(android.R.color.holo_green_dark,
android.R.color.holo_red_dark,
android.R.color.holo_blue_dark,
android.R.color.holo_orange_dark);
return inflater.inflate(R.layout.fragment_notifications, container, false);
}
@Override
public void onRefresh() {
Log.d("Notifications", "onRefresh called from SwipeRefreshLayout");
}
// Used to access my Parse Server database
public void accessDataBase() {
ParseQuery query = new ParseQuery("OurPushes");
query.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
List<String> subject = new ArrayList<>();
List<String> body = new ArrayList<>();
for (ParseObject pushObject : objects) {
if(pushObject.getString("title") != "")
subject.add(pushObject.getString("title"));
else
subject.add("");
if(pushObject.getString("alert") != "")
body.add(pushObject.getString("alert"));
else
body.add("");
}
Collections.reverse(subject);
Collections.reverse(body);
if(getActivity() != null) {
mAdapter = new CustomAdapter(subject, body);
mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.rv);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
}
}
else {
Log.d("Brand", "Error: " + e.getMessage());
}
}
});
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
}
这是我的 XML 代码 (fragment_notifications.xml):
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
这是我的 Android 显示器上的结果。请注意我在 OnRefresh() 中的 Log.d 语句没有被调用,尽管我在我的 Android 设备上拉动刷新:
06-16 17:57:13.022 2668-2668/xxxxxxx.xxxxxx W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
06-16 17:57:13.314 2668-2718/xxxxxxx.xxxxxx D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-16 17:57:13.317 2668-2668/xxxxxxx.xxxxxx D/Atlas: Validating map...
06-16 17:57:13.353 2668-2718/xxxxxxx.xxxxxx I/Adreno: EGLInit: QTI Build: 03/04/15, eeab148,
06-16 17:57:13.365 2668-2718/xxxxxxx.xxxxxx I/OpenGLRenderer: Initialized EGL, version 1.4
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (611)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (611)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (611)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (611)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (612)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (612)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (612)
06-16 17:57:13.366 2668-2718/xxxxxxx.xxxxxx I/Adreno: GetNativeFormatFromQctPixelFormat: Invalid qct format (612)
06-16 17:57:13.373 2668-2718/xxxxxxx.xxxxxx D/OpenGLRenderer: Enabling debug mode 0
06-16 17:57:13.394 2668-2668/xxxxxxx.xxxxxx E/RecyclerView: No adapter attached; skipping layout
06-16 17:57:13.445 2668-2719/xxxxxxx.xxxxxx I/OpenGLRenderer: WorkerThread::readyToRun:hwuiTask1
06-16 17:58:46.962 2668-4140/xxxxxxx.xxxxxx I/OpenGLRenderer: WorkerThread::readyToRun:hwuiTask2
我知道你们中的一些人可能会提到,我知道 Parse 即将结束。我正在使用解析服务器。我的解析服务器托管在 Heroku 上,而不是 Parse.com。
在此先感谢您的帮助。如果您需要任何其他信息,请询问。
最佳答案
在 onCreateView 中,您将返回一个与您使用 OnRefreshListener 设置的 View 不同的 View 。请注意,您调用了 inflater.inflate(...) 两次,创建了两个单独的 View 。试试这个:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
accessDataBase();
view = inflater.inflate(R.layout.fragment_notifications, container, false);
swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorSchemeColors(android.R.color.holo_green_dark,
android.R.color.holo_red_dark,
android.R.color.holo_blue_dark,
android.R.color.holo_orange_dark);
return view;
}
关于java - Android:SwipeRefreshLayout 不会调用 OnRefresh(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37870096/
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt