我有RecycerView
,它有分页,当我滚动一些时候,它正在崩溃。当我慢慢滚动时,它没有崩溃。我已经提供了适配器和活动代码。请让我知道我在这里做错了什么。我已经搜索了相同的问题,但无法在此处捕获错误。
private class GetTrending extends AsyncTask<Void, Void, Void> {
BufferedReader bufferedReader = null;
private StringBuffer stringBuffer = new StringBuffer();
private JSONArray jArray = new JSONArray();
private int pageNum;
private boolean value;
public GetTrending(int pageNum, boolean value) {
this.pageNum = pageNum;
this.value = value;
}
@Override
protected Void doInBackground(Void... params) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet();
URI uri = new URI(getString(R.string.url) +
"products?bestsellers=on&items_per_page=24&page=" + pageNum + mWholeSaleUrlTag);
httpGet.setURI(uri);
httpGet.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials(getString(R.string.username), getString(R.string.password)),
HTTP.UTF_8, false));
HttpResponse httpResponse;
Log.e("Trending-Before", "Date" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()));
httpResponse = httpClient.execute(httpGet);
Log.e("Trending-After", "New Date" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()));
InputStream inputStream = httpResponse.getEntity().getContent();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//Log.e("Hi", String.valueOf(bufferedReader));
String readLine = bufferedReader.readLine();
while (readLine != null) {
stringBuffer.append(readLine);
//stringBuffer.append("\n");
readLine = bufferedReader.readLine();
}
//Log.e("BestSellers", String.valueOf(stringBuffer));
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
try {
JSONObject prodObjects = new JSONObject(String.valueOf(stringBuffer));
jArray = prodObjects.optJSONArray("products");
if (jArray.length() < 24) {
shouldFetchTrending = false;
}
for (int i = 0; i < jArray.length(); i++) {
Home home = new Home();
prodObjects = jArray.getJSONObject(i);
home.setProduct_id(prodObjects.getString("product_id"));
// Log.e("Trending id", jobj.getString("product_id"));
home.setProduct_name(prodObjects.getString("product"));
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
home.setProduct_price(nf.format(Double.parseDouble(prodObjects.getString("price"))));
home.setProduct_listprice(nf.format(Double.parseDouble(prodObjects.getString("list_price"))));
String mAmount = prodObjects.getString("amount");
home.setAmount(mAmount);
Item item = new Item();
item.setName(prodObjects.getString("product"));
item.setProductId(prodObjects.getString("product_id"));
item.setPrice(nf.format(Double.parseDouble(prodObjects.getString("price"))));
item.setListPrice(nf.format(Double.parseDouble(prodObjects.getString("list_price"))));
item.setImage(prodObjects.getJSONObject("main_pair").getJSONObject("detailed").getString("image_path"));
item.setAmount(mAmount);
home.setProduct_image(prodObjects.getJSONObject("main_pair").getJSONObject("detailed").getString("image_path"));
if (prodObjects.getString("status").equalsIgnoreCase("A") && !prodObjects.getString("amount").equalsIgnoreCase("0")) {
Sports.add(home);
trendingItemList.add(item);
}
}
// Log.e("Length", String.valueOf(Sports.size()));
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
shouldFetchTrending = true;
if (value) {
trendingItemAdapter = new ItemAdapter(HomeActivity.this, trendingItemList);
mTrendingRecyclerView.setAdapter(trendingItemAdapter);
}
trendingItemAdapter.notifyDataSetChanged();
mTrendingRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(HomeActivity.this, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
((CardView) view).setCardElevation(100);
Intent myintent = new Intent(HomeActivity.this, ProductPageActivity.class);
myintent.putExtra("Prodid", trendingItemList.get(position).getProductId());
myintent.putExtra("FromHome", "Home");
startActivity(myintent);
}
}));
try {
for (int i = 0; i < Sports.size(); ++i) {
trendinglinear[i].setVisibility(View.VISIBLE);
tname[i].setText(Sports.get(i).getProduct_name());
tprice[i].setText(Sports.get(i).getProduct_price());
((View) tname[i].getParent()).setTag(Sports.get(i).getProduct_id());
String[] simg = new String[25];
simg[i] = Sports.get(i).getProduct_image();
//Log.e("image", simg[i]);
Picasso.with(getApplicationContext()).load(simg[i]).error(R.drawable.ic_launcher).resize(400, 400).into(timage[i]);
}
} catch (Exception e) {
//Toast.makeText(HomeActivity.this, "Failed to connect to internet Try again !", Toast.LENGTH_SHORT).show();
}
}
}
public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ViewHolder> {
private List<Item> itemList;
private Context context;
private int lastPosition = -1;
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.home_recycler_item, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Item item = itemList.get(position);
holder.tvName.setText(item.getName());
if(Integer.valueOf(item.getAmount()) == 0)
holder.tvOutofstack.setVisibility(View.VISIBLE);
else holder.tvOutofstack.setVisibility(View.INVISIBLE);
holder.tvPrice.setText(item.getPrice());
Picasso.with(context).load(item.getImage()).into(holder.ivImage);
setAnimation(holder.cardView, position);
}
@Override
public int getItemCount() {
return itemList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView tvName,tvOutofstack;
public TextView tvPrice;
public ImageView ivImage;
public CardView cardView;
public ViewHolder(View itemView) {
super(itemView);
tvName = (TextView) itemView.findViewById(R.id.tv_name);
tvOutofstack = (TextView) itemView.findViewById(R.id.item_adapter_tv);
tvPrice = (TextView) itemView.findViewById(R.id.tv_price);
ivImage = (ImageView) itemView.findViewById(R.id.iv_image);
cardView = (CardView) itemView.findViewById(R.id.card_view);
}
}
public ItemAdapter(Context context, List<Item> itemList) {
this.itemList = itemList;
this.context = context;
}
private void setAnimation(View viewToAnimate, int position)
{
// If the bound view wasn't previously displayed on screen, it's animated
if (position > lastPosition)
{
Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
viewToAnimate.startAnimation(animation);
lastPosition = position;
}
}
}
显示某些错误(日志):
应用程序正在崩溃的内存管理失败,这里的每个项目都分配动画,应用动画不清楚。我已经解决了你的问题花了一天,它为我工作。
@Override public void onViewDetachedFromWindow(ViewHolder holder) {
super.onViewDetachedFromWindow(holder);
((ViewHolder)holder).clearAnimation();
}
在我的ViewHolder added方法中:
public void clearAnimation() {
itemView.clearAnimation();
}
在我的应用程序,我有品牌页脚在所有屏幕滚动结束(屏幕有滚动)和静态在屏幕底部时(没有滚动)。 但我面临的问题,以实现这与屏幕,其中有列表。我正在使用RecycerView显示列表。我想在RecycerView的结尾显示品牌页脚,当它有滚动时,它将在底部滚动时可见。这是可以用带有页脚的RecycerView实现的。 但是当RecycerView没有滚动(当列表中的项目很少时),我希望页脚固定在屏幕底
在我的应用程序中,我使用,当用户向下滚动时,它可以继续加载图像。但这让我遇到了一个我无法解决的问题。基本上,我是说 所以,我真的很困惑如何做到这一点。作为额外的信息,这是我的整个活动: 希望你们能帮帮我:)
我已经用一些视频(比如10个)实现了一个回收器视图。单击任何项目都会打开一个上,其中包含所有项目显示单击的一个(来自)。之后,用户只能从那里滚动到其他项目。一切正常。 唯一的问题是当recyclerview项单击viewpager2打开的位置时滚动。 无论何时选择任何项目(第10个)。viewpager首先打开,然后滚动到(第10)个位置。我想不滚动直接打开viewpager2的第10个位置。任何
滚动条显示位置都是在最右侧或最底部,怎样控制滚动条显示在某一个div里面或为一个位置? 不是说滚动位置,滚动条的显示位置
问题内容: 我有一个position:fixed的元素,所以随页面滚动,但是我想要它如何。当用户向上滚动时,我希望元素在某个点处停止滚动,比如说距页面顶部250px时,这可能吗?任何帮助或建议都将有所帮助,谢谢! 我有一种感觉,我需要使用jquery来做到这一点。我尝试获取用户所在位置的滚动或位置,但感到非常困惑,是否有任何jQuery解决方案? 问题答案: 这是我刚刚编写的一个快速jQuery插
本文向大家介绍jQuery实现滚动条滚动到子元素位置(方便定位),包括了jQuery实现滚动条滚动到子元素位置(方便定位)的使用技巧和注意事项,需要的朋友参考一下 话不多说,请看代码: jQuery: 以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持呐喊教程!