- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试获取 xml 数据,然后将其解析为 JSON,我使用 OkHttp 作为连接。我设法从 LOG 获取数据,但当我登录到适配器且结果大小为 0 时,无法在 RecyclerView 中显示它
我设置了对模型和共享首选项的响应
问题的关键是我只是不明白如何从演示者那里获取响应,然后将其设置到主 fragment 中的适配器。
公共(public)类父类别{
@SerializedName("idkategori")
@Expose
private String idkategori;
@SerializedName("namakategori")
@Expose
private String namakategori;
@SerializedName("fileicon")
@Expose
private String fileicon;
@SerializedName("subkategori")
@Expose
private SubCategories subkategori;
public ParentCategories(Parcel in) {
this.idkategori = in.readString();
this.namakategori = in.readString();
this.fileicon = in.readString();
}
public ParentCategories() {
}
public String getIdkategori() {
return idkategori;
}
public void setIdkategori(String idkategori) {
this.idkategori = idkategori;
}
public String getNamakategori() {
return namakategori;
}
public void setNamakategori(String namakategori) {
this.namakategori = namakategori;
}
public String getFileicon() {
return fileicon;
}
public void setFileicon(String fileicon) {
this.fileicon = fileicon;
}
public SubCategories getSubkategori() {
return subkategori;
}
public void setSubkategori(SubCategories subkategori) {
this.subkategori = subkategori;
}
}
public class CategoriesPresenter {
....
public void onResponse(Call call, Response response) throws IOException {
String mMessage = response.body().string();
JSONObject jsonObj = null;
try {
jsonObj = XML.toJSONObject(mMessage);
JSONObject jsonObject = new JSONObject(jsonObj.toString());
JSONObject object = jsonObject.getJSONObject("posh");
String attr2 = object.getString("resultcode");
com.davestpay.apphdi.helper.Log.d("hasil", String.valueOf(object));
if (attr2.equalsIgnoreCase("0000")) {
String idAgen = object.getString("idagen");
int jumlahKategori = object.getInt("jumlahkategori");
JSONArray category = object.getJSONArray("kategori");
List<ParentCategories> parentCategories = new ArrayList<ParentCategories>();
for (int i = 0; i < category.length(); i++) {
ParentCategories categories = new ParentCategories();
JSONObject c = category.getJSONObject(i);
Log.d(TAG, "onResponseC: "+c);
String idKategori = c.getString("idkategori");
String namaKategori = c.getString("namakategori");
Log.d(TAG, "onResponseNamaKategori: "+namaKategori);
String fileIcon = c.getString("fileicon");
JSONObject subCategories = c.getJSONObject("subkategori");
JSONArray subCategory = subCategories.getJSONArray("kategori2");
Log.d(TAG, "onResponseSubCategories: "+subCategory);
for (int subCatPosition = 0; subCatPosition < subCategory.length(); subCatPosition++) {
SecondCategories secondCategories = new SecondCategories();
List<SecondCategories> listSecondCategories = new ArrayList<>();
JSONObject sc = subCategory.getJSONObject(subCatPosition);
String secIdKategori = sc.getString("idkategori");
String secNamaKategori = sc.getString("namakategori");
String secFileIcon = sc.getString("fileicon");
secondCategories.setIdkategori(secIdKategori);
secondCategories.setNamakategori(secNamaKategori);
secondCategories.setFileicon(secFileIcon);
listSecondCategories.add(secondCategories);
}
categories.setIdkategori(idKategori);
categories.setNamakategori(namaKategori);
categories.setFileicon(fileIcon);
parentCategories.add(categories);
Log.d(TAG, "onResponseFinalCategories: "+parentCategories);
}
iCategories.onSuccessCategories(parentCategories);
preferenceHelper.clear(PreferenceHelper.CATEGORIES);
preferenceHelper.putList(PreferenceHelper.CATEGORIES, parentCategories);
} else {
Log.d(TAG, "onResponse: ");
}
} catch (JSONException e) {
com.davestpay.apphdi.helper.Log.e("JSON exception", e.getMessage());
e.printStackTrace();
}
}
}
private void getInit() {
if (preferenceHelper != null) {
idAgen = preferenceHelper.getString(PreferenceHelper.ID_AGEN);
namaAgen = preferenceHelper.getString(PreferenceHelper.NAMA_AGEN);
password = preferenceHelper.getString(PreferenceHelper.PASSWORD);
categories = preferenceHelper.getList(PreferenceHelper.CATEGORIES, ParentCategories[].class);
}
authPresenter = new AuthPresenter(getContext());
presenter = new CategoriesPresenter();
presenter.setBaseView(this);
presenter.onCreate(getContext());
if (authPresenter.isLoggedIn()) {
// kategori.setText(categories.toString());
presenter.getCategories(idAgen, password, counter);
}
kategori = mView.findViewById(R.id.kategori);
categories = new ArrayList<>();
rvMain = mView.findViewById(R.id.rv_categories);
adapter = new CategoriesListViewAdapter(getContext(), categories);
layoutManager = new LinearLayoutManager(getdActivity());
adapter.notifyDataSetChanged();
rvMain.setLayoutManager(layoutManager);
rvMain.setAdapter(adapter);
}
最佳答案
这就是问题所在。
categories = new ArrayList<>();
在这里,您正在将类别初始化为 new ArrayList<>();这就像您正在创建一个新的数组列表。只需删除此行即可。
关于java - 如何从 Presenter 解析 JSON 并设置为 RecyclerView(Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57984451/
let appDelegate = UIKit.UIApplication.shared.delegate! if let tabBarController = appDelegate
我的演示文稿终于成功了。我的第一个屏幕有一个主要的 activity,第二个屏幕有一个 Presentation。我的问题是,我无法更改演示 View 中的内容。 为什么我不能在第二个屏幕上显示演示文
这个问题在这里已经有了答案: ios, getting a pointer to a controller from a view (5 个答案) 关闭 4 年前。 我有一个 uiview 文件,我
我有一个表示小部件的 View 类和一个随附的演示者类。我还有一个 View 类,用于拥有小部件的窗口,以及窗口 View 的随附演示者。窗口操作小部件,所以我需要窗口展示器与小部件展示器进行通信。可
关闭相机后。它给了我这个警告:在演示过程中尝试继续演示! - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picke
由于这个错误,我无法切换到另一个 View Controller 。我想在成功扫描二维码后切换到另一个 View Controller 。 2015-01-27 17:59:16.093 *[5416
有时它会发生 - 从代码的不同地方 - 我们想要做 UIViewController.presentViewController(a, b, c),有时我们已经在呈现了,在这种情况下我们得到: 警告:
这是我的第一个 iOS 应用程序。 所以我有一个 UIVIewController 和一个 UITableView,其中我按顺序集成了一个 UISearchBar 和一个 UISearchContro
我的模式允许一个特定的元素是可选的,但是当我稍后在文件中遇到一个不同的也是可选的元素时,我需要前一个元素存在。我如何通过 XSD 确保这一点? 例子: true 应该是有效的,
我正在使用 xcode 4.5.2 并为相机按钮创建了自己的 OverlayViewController。 现在,当我的委托(delegate) Controller - TakePhotoViewC
如何在 MVP 中创建 View ? Presenter 是否总是创建它们(除了 subview 的 View 之外)?或者它是一个单独的第三方组件或应用程序或创建它们的东西? 我们还要补充一点,我可
当我调用viewController.presentViewController时,如果已经存在另一个 Controller ,则会出现以下警告。 Warning: Attempt to presen
我有一个关于 React Native 的模块,并在这个问题的标题中抛出错误。这是模块的代码,我不知道 swift 或 Objective-C,所以我需要你像“swift for idiots”一样解
我在 didSelectRowAtIndexPath 中选择一个 segue 时收到上面的警告。这发生在 iPad 上。 iPhone 给出了不同的警告,我会看看是否可以解决这个问题。 我在方法中确实
我的应用程序中有一个包含两个场景的 StoryBoard - 它使用自动转场(在 IB 中创建)。当在第一个 UIViewController 中单击按钮时,第二个 UIViewController
如何在成功验证登录后转到我的第二页? 我已经从登录页面 View Controller (不是登录按钮)拉出一个 segue 到下一页,并将该 segue 命名为“nextPage”。 (如果我从登录
我正在构建一个应用程序,最近发现了由传统转场引起的巨大内存泄漏。因此我了解了 unwind segue。如果我简单地使用,一切都很好: @IBAction func prepareForUnw
我不知道如何将按钮添加到 link_to_add_fields 中 在我制作的 Rails 应用程序中。 我尝试在各处添加 class: "btn btn-mini btn-info",但我一直收到
大家好,感谢阅读。我正在制作一个应用程序,您可以在其中拍照并从相机胶卷中检索照片并将其显示在 View 中。问题是,当我尝试使用调出相机胶卷的按钮时,出现如上标题中的错误“演示正在进行中”。 如果我注
我有一个模型,其中有两个字段在技术上可以为空。字段名称是 :is_activated 和 :activated_at。 :activated_at 仅在 :is_activated 设置为 true
我是一名优秀的程序员,十分优秀!