- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每当调用 onActivity 结果时,Recycler listview 在项目之间添加额外的空间。它发生在每个 ListView 中。
我的java代码
package com.kahoindia.dev.fragments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import com.kahoindia.dev.activities.KaHOAppController;
import com.kahoindia.dev.activities.KaHOComposeTaskActivity;
import com.kahoindia.dev.activities.KaHOTaskDetailActivity;
import com.kahoindia.dev.activities.R;
import com.kahoindia.dev.customclasses.KaHOTextView;
import com.kahoindia.dev.customclasses.RecyclerTouchListener;
import com.kahoindia.dev.helpers.Const;
import com.kahoindia.dev.helpers.DateUtility;
import com.kahoindia.dev.helpers.LayoutUtility;
import com.kahoindia.dev.interfaces.KaHOIRecyclerViewItemClickListener;
import com.kahoindia.dev.interfaces.KaHOViewInterface;
import com.kahoindia.dev.managerclasses.KaHObTicket;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.HashMap;
/**
* Created by KaHO PC-1 on 12-08-2016.
*/
public class KaHOPendingTaskFragment extends KaHOFragment {
private RecyclerView mRecyclerView;
private JSONArray mPendingTaskArray;
private boolean mOnLoad = false;
private PendingTaskAdapter mAdapter;
private FloatingActionButton mBtnAssignTask;
private boolean mRecExists;
private int mPageNum;
private int mHolderPos;
private PendingTaskAdapter.ViewHolder mHolder;
private ProgressBar mProgressbar;
private String mTotalPages;
private KaHOTextView mTxtNoData;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_task_pending_list, container, false);
try {
mRecyclerView = (RecyclerView) view.findViewById(R.id.pendingList);
mBtnAssignTask = (FloatingActionButton) view.findViewById(R.id.assignTask);
mProgressbar = (ProgressBar) view.findViewById(R.id.progress_bar);
mTxtNoData = (KaHOTextView) view.findViewById(R.id.txtNoData);
mRecExists = true;
mOnLoad = true;
mPageNum = 1;
mHolderPos = 0;
mAdapter = new PendingTaskAdapter();
mPendingTaskArray = new JSONArray();
mRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), mRecyclerView, new KaHOIRecyclerViewItemClickListener() {
@Override
public void onClick(View view, int position) {
try {
JSONObject selectedObject = mPendingTaskArray.getJSONObject(position);
Intent intent = new Intent(getActivity(), KaHOTaskDetailActivity.class);
intent.putExtra("taskObject", selectedObject.toString());
startActivityForResult(intent, 1);
} catch (Exception e) {
e.getStackTrace();
}
}
@Override
public void onLongClick(View view, int position) {
}
}));
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
int currentFirstVisibleItem;
int currentVisibleItemCount;
int currentScrollState;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
this.currentScrollState = newState;
isScrollCompleted();
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
this.currentFirstVisibleItem = dx;
this.currentVisibleItemCount = dy;
}
private void isScrollCompleted() {
try {
if (this.currentVisibleItemCount > 0 && mRecExists && this.currentScrollState == RecyclerView.SCROLL_STATE_IDLE) {
mPageNum++;
mOnLoad = false;
if (mPageNum <= Integer.parseInt(mTotalPages)) {
mHolder = (PendingTaskAdapter.ViewHolder) mRecyclerView.findViewHolderForAdapterPosition(mHolderPos);
mHolder.pBar.setVisibility(View.VISIBLE);
getPendingTask();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
mBtnAssignTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), KaHOComposeTaskActivity.class);
startActivityForResult(intent, 2);
}
});
getPendingTask();
} catch (Exception e) {
e.printStackTrace();
}
return view;
}
public void getDataOnLoad() {
if (mOnLoad) {
getPendingTask();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.setActivityTag(getActivity().getLocalClassName());
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
mHolder = null;
mOnLoad = true;
mPendingTaskArray = new JSONArray();
mPageNum = 1;
getPendingTask();
} else if (requestCode == 2 && resultCode == Activity.RESULT_OK) {
mHolder = null;
mOnLoad = true;
mPendingTaskArray = new JSONArray();
mPageNum = 1;
getPendingTask();
}
}
private void getPendingTask() {
HashMap<String, String> params = new HashMap<>();
params.put("ayCode", KaHOAppController.getCurrentAY());
params.put("Mine", "1");
params.put("Others", "0");
params.put("Is_Pending", "1");
params.put("PageNo", String.valueOf(mPageNum));
params.put("NoOfRec", String.valueOf(Const.mNumOfRecords));
if (mOnLoad) {
mProgressbar.setVisibility(View.VISIBLE);
}
KaHObTicket kaHObTicket = new KaHObTicket();
kaHObTicket.getTask(params, "GetTaskList", mContext, new KaHOViewInterface() {
@Override
public void viewHandler(Object viewResponse) {
JSONObject responseObject = (JSONObject) viewResponse;
try {
if (!mOnLoad && mHolder != null) {
mHolder.pBar.setVisibility(View.GONE);
} else {
mProgressbar.setVisibility(View.GONE);
}
String msg = responseObject.getString("msg");
String cusmsg = responseObject.getString("cusmsg");
String code = responseObject.getString("code");
if (msg.equals("Success") && code.equals(Const.SUCCESS_CODE)) {
JSONArray array = responseObject.getJSONArray("GetTaskList");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
if (i == 0) {
mTotalPages = jsonObject.getString("Total_Pages");
}
mPendingTaskArray.put(jsonObject);
}
mRecExists = true;
generateList();
} else {
mRecExists = false;
if (mOnLoad) {
mTxtNoData.setVisibility(View.VISIBLE);
mTxtNoData.setText(cusmsg);
}
}
mOnLoad = false;
} catch (Exception e) {
mProgressbar.setVisibility(View.GONE);
e.printStackTrace();
}
}
});
}
private void generateList() {
try {
if (mOnLoad) {
LayoutUtility.setRecyclerListView(mRecyclerView, mContext);
mRecyclerView.setAdapter(mAdapter);
} else {
mAdapter.notifyDataSetChanged();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public class PendingTaskAdapter extends RecyclerView.Adapter<PendingTaskAdapter.ViewHolder> {
public class ViewHolder extends RecyclerView.ViewHolder {
public KaHOTextView txtAssignedBy, txtAssignedTo, txtTitle, txtDate;
public ProgressBar pBar;
public ViewHolder(View view) {
super(view);
txtAssignedBy = (KaHOTextView) view.findViewById(R.id.txtAssignedBy);
txtAssignedTo = (KaHOTextView) view.findViewById(R.id.txtAssignedTo);
txtTitle = (KaHOTextView) view.findViewById(R.id.txtTitle);
txtDate = (KaHOTextView) view.findViewById(R.id.txtDate);
pBar = (ProgressBar) view.findViewById(R.id.progressBar);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.template_task_list, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
try {
mHolderPos = position;
JSONObject taskObject = mPendingTaskArray.getJSONObject(position);
holder.txtAssignedBy.setText(taskObject.getString("Created_By_Name"));
holder.txtAssignedTo.setText(taskObject.getString("Assigned_To_Name"));
holder.txtTitle.setText(taskObject.getString("Title"));
holder.txtDate.setText(DateUtility.changeDateFormat(taskObject.getString("Date"), "dd/MM/yyyy", "dd MMM"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int getItemCount() {
return mPendingTaskArray.length();
}
}
}
fragment_task_pending_list.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/tools">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pendingList"/>
<include
android:id="@+id/progress_bar"
layout="@layout/progress_bar"></include>
<com.kahoindia.dev.customclasses.KaHOTextView
android:id="@+id/txtNoData"
style="@style/kaho_content_label_textview_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:text="@string/task_no_data"
android:visibility="gone"
custom:CustomTextViewFont="@string/kaho_segoeui_regular_font" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
app:backgroundTint="@color/floatingIconRed"
android:id="@+id/assignTask"
android:src="@drawable/floating_plus"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
和适配器模板template_task_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:custom="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.kahoindia.dev.customclasses.KaHOTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/kaho_listview_label_heading"
android:text="From : "
custom:CustomTextViewFont="@string/kaho_segoeui_semi_light_font"/>
<com.kahoindia.dev.customclasses.KaHOTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/kaho_listview_label_heading"
android:id="@+id/txtAssignedBy"
custom:CustomTextViewFont="@string/kaho_segoeui_semi_light_font"/>
<com.kahoindia.dev.customclasses.KaHOTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/kaho_listview_label_heading"
android:text="To : "
custom:CustomTextViewFont="@string/kaho_segoeui_semi_light_font"
android:paddingLeft="10dp"/>
<com.kahoindia.dev.customclasses.KaHOTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/kaho_listview_label_heading"
android:id="@+id/txtAssignedTo"
custom:CustomTextViewFont="@string/kaho_segoeui_semi_light_font"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:weightSum="2">
<com.kahoindia.dev.customclasses.KaHOTextView
android:id="@+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:singleLine="true"
style="@style/kaho_content_small_textview_style"
custom:CustomTextViewFont="@string/kaho_segoeui_regular_font"/>
<com.kahoindia.dev.customclasses.KaHOTextView
android:id="@+id/txtDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/kaho_content_small_textview_style"
custom:CustomTextViewFont="@string/kaho_segoeui_regular_font"
android:gravity="right" />
</LinearLayout>
<include
android:id="@+id/progressBar"
layout="@layout/lazy_loading_progress_bar"/>
</LinearLayout>
</LinearLayout>
最佳答案
实际上,您将 adapter
设置为 recyclerview
的地方是错误的。您必须在 onCreate
方法中使用空 arraylist
setAdapter
并且当您在 startActivityResult
中获取更新列表时,您只需要notifyDataSetChanged
。供大家引用
在 onCreate 中
mAdapter = new PendingTaskAdapter(new ArrayList<YourListClassName>(); // empty arraylist
mRecyclerView.setAdatper(mAdapter);
然后在 generateList() 方法中
mAdapter.setData(YourUpdatedList);
mAdapter.notifyDataSetChanged();
在 PendingTaskAdatper 中创建一个方法 setData 以获取如下所示的更新列表
private void setData(List<YourListClassName> updatedList){
mUpdatedList = updatedList;}
现在你应该得到预期的输出
关于android - 在回收站 ListView 项目之间添加了大空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41235268/
我创建了一个用户可以添加测试的字段。这一切运行顺利我只希望当用户点击(添加另一个测试)然后上一个(添加另一个测试)删除并且这个显示在新字段中。 所有运行良好的唯一问题是点击(添加另一个字段)之前添加另
String[] option = {"Adlawan", "Angeles", "Arreza", "Benenoso", "Bermas", "Brebant
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在努力将 jQuery 滚动功能添加到 nav-tab (Bootstrap 3)。我希望用户能够选择他们想要的选项卡,并在选项卡内容中有一个可以平滑滚动到 anchor 的链接。这是我的代码,可
我正在尝试在用户登录后再添加 2 个 ui 选项卡。首先,我尝试做一个之后。 $('#slideshow').tabs('remove', '4'); $("#slideshow ul li:last
我有一个包含选择元素的表单,我想通过选择添加和删除其中一些元素。这是html代码(这里也有jsfiddle http://jsfiddle.net/txhajy2w/):
正在写这个: view.backgroundColor = UIColor.white.withAlphaComponent(0.9) 等同于: view.backgroundColor = UICo
好的,如果其中有任何信息,我想将这些列添加到一起。所以说我有 账户 1 2 3 . 有 4 个帐户空间,但只有 3 个帐户。我如何创建 java 脚本来添加它。 最佳答案 Live Example H
我想知道是否有一种有效的预制算法来确定一组数字的和/差是否可以等于不同的数字。示例: 5、8、10、2,使用 + 或 - 等于 9。5 - 8 = -3 + 10 = 7 + 2 = 9 如果有一个预
我似乎有一个卡住的 git repo。它卡在所有基本的添加、提交命令上,git push 返回所有内容为最新的。 从其他帖子我已经完成了 git gc 和 git fsck/ 我认为基本的调试步骤是
我的 Oracle SQL 查询如下- Q1- select hca.account_number, hca.attribute3, SUM(rcl.extended_amou
我正在阅读 http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingG
我正在尝试添加一个“加载更多”按钮并限制下面的结果,这样投资组合页面中就不会同时加载 1000 个内容,如下所示:http://typesetdesign.com/portfolio/ 我对 PHP
我遇到这个问题,我添加了 8 个文本框,它工作正常,但是当我添加更多文本框(如 16 个文本框)时,它不会添加最后一个文本框。有人遇到过这个问题吗?提前致谢。 Live Link: JAVASCRIP
add/remove clone first row default not delete 添加/删除克隆第一行默认不删除&并获取正确的SrNo(例如:添加3行并在看到问题后删除SrNo.2)
我编码this ,但删除按钮不起作用。我在控制台中没有任何错误.. var counter = 0; var dataList = document.getElementById('materi
我有一个类似数组的对象: [1:数组[10]、2:数组[2]、3:数组[2]、4:数组[2]、5:数组[3]、6:数组[1]] 我正在尝试删除前两个元素,执行一些操作,然后将它们再次插入到同一位置。
使用的 Delphi 版本:2007 你好, 我有一个 Tecord 数组 TInfo = Record Name : String; Price : Integer; end; var Info
我使用了基本的 gridster 代码,然后我声明了通过按钮添加和删除小部件的函数它工作正常但是当我将调整大小功能添加到上面的代码中时,它都不起作用(我的意思是调整大小,添加和删除小部件) 我的js代
title 323 323 323 title 323 323 323 title 323 323 323 JS $(document).keydown(function(e){
我是一名优秀的程序员,十分优秀!