永发信息网

在fragment中使用xutils怎么联网

答案:2  悬赏:0  手机版
解决时间 2021-01-25 16:36
  • 提问者网友:回忆在搜索
  • 2021-01-25 09:28
在fragment中使用xutils怎么联网
最佳答案
  • 五星知识达人网友:大漠
  • 2021-01-25 10:11
好像xutils框架目前还不支持fragment的反射,看了下,比较好改,主要修改ViewFinder。
修改一:
ViewUtils.java

[java] view plain copy
public static void inject(Fragment fragment) {
injectObject(fragment, new ViewFinder(fragment));
}

修改二:

ViewFinder.java

[java] view plain copy
import android.app.Activity;
import android.content.Context;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.support.v4.app.Fragment;
import android.view.View;

public class ViewFinder {

private View view;
private Activity activity;
private Fragment fragment;
private PreferenceGroup preferenceGroup;
private PreferenceActivity preferenceActivity;

public ViewFinder(View view) {
this.view = view;
}

public ViewFinder(Activity activity) {
this.activity = activity;
}

public ViewFinder(Fragment fragment) {
this.fragment = fragment;
}

public ViewFinder(PreferenceGroup preferenceGroup) {
this.preferenceGroup = preferenceGroup;
}

public ViewFinder(PreferenceActivity preferenceActivity) {
this.preferenceActivity = preferenceActivity;
this.activity = preferenceActivity;
}

public View findViewById(int id) { // 修改这里
// View v = activity == null ? view.findViewById(id) : activity.findViewById(id);
View v = null;
if(activity != null) {
v = activity.findViewById(id);
} else if(this.fragment != null) {
v = this.fragment.getView().findViewById(id);
} else {
v = view.findViewById(id);
}
return v;
}

public View findViewByInfo(ViewInjectInfo info) {
return findViewById((Integer) info.value, info.parentId);
}

public View findViewById(int id, int pid) {
View pView = null;
if (pid > 0) {
pView = this.findViewById(pid);
}

View view = null;
if (pView != null) {
view = pView.findViewById(id);
} else {
view = this.findViewById(id);
}
return view;
}

@SuppressWarnings("deprecation")
public Preference findPreference(CharSequence key) {
return preferenceGroup == null ? preferenceActivity.findPreference(key) : preferenceGroup.findPreference(key);
}

public Context getContext() {
if (view != null) return view.getContext();
if (activity != null) return activity;
if (preferenceActivity != null) return preferenceActivity;
if (fragment != null) return fragment.getActivity();
return null;
}
}
全部回答
  • 1楼网友:像个废品
  • 2021-01-25 11:27
搜一下:在fragment中使用xutils怎么联网
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯