조각 코드는응용 프로그램은에서 Andriod에 자사의 메인 스레드 (중포 기지 데이터베이스)에 너무 많은 일을 할 수있다
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
list = new ArrayList<>();
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
for (DataSnapshot dataSnapshot2 : dataSnapshot1.child("Posts").getChildren()) {
try {
Model listdata = new Model();
Model for_post_details = dataSnapshot2.child("info").getValue(Model.class);
//Toast.makeText(getActivity(), ""+dataSnapshot1.child("username").getValue(), Toast.LENGTH_SHORT).show();
String path = for_post_details.getPath();
String location = for_post_details.getLocation();
String caption = for_post_details.getCaption();
String username = "" + dataSnapshot1.child("username").getValue();
listdata.setPath(path);
listdata.setLocation(location);
listdata.setCaption(caption);
listdata.setUsername(username);
list.add(listdata);
} catch (Exception ignored) {
}
}
}
Adapter recyclerview = new Adapter(list, getActivity());
RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(getActivity());
recycler.setLayoutManager(layoutmanager);
recycler.setItemAnimator(new DefaultItemAnimator());
recycler.setAdapter(recyclerview);
}
@Override
public void onCancelled(DatabaseError error) {
}
});
어댑터 코드는
public class Adapter extends RecyclerView.Adapter<Adapter.MyHoder> {
List<Model> list;
Context context;
public Adapter(List<Model> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public MyHoder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.recycler_trending,parent,false);
MyHoder myHoder = new MyHoder(view);
return myHoder;
}
@Override
public void onBindViewHolder(MyHoder holder, int position) {
Model mylist = list.get(position);
holder.caption.setText(mylist.getCaption());
holder.location.setText(mylist.getLocation());
holder.username_top.setText(mylist.getUsername());
holder.username_bottom.setText(mylist.getUsername());
Glide.with(context)
.load(mylist.getPath())
.into(holder.image);
}
@Override
public int getItemCount() {
return list.size();
}
class MyHoder extends RecyclerView.ViewHolder{
TextView total_likes, caption, location, username_top, username_bottom;
ImageView image;
ImageButton like, share;
public MyHoder(View itemView) {
super(itemView);
total_likes = (TextView) itemView.findViewById(R.id.total_likes);
caption = (TextView) itemView.findViewById(R.id.caption);
username_top = (TextView) itemView.findViewById(R.id.username_top);
username_bottom = (TextView) itemView.findViewById(R.id.username_bottom);
location = (TextView) itemView.findViewById(R.id.location);
image = (ImageView) itemView.findViewById(R.id.image);
like = (ImageButton) itemView.findViewById(R.id.like);
share = (ImageButton) itemView.findViewById(R.id.share);
}
}
이 코드 Instagram과 같은 앱을 만드는 데 사용하고 있습니다.
코드는 정상적으로 실행되지만 UI가 느리며 스크롤 속도가 느려지고 응용 프로그램이 중지됩니다.
이 메시지가 나타납니다.
I/Choreographer (1378) : 65 프레임 건너 뛰기! 응용 프로그램은 일 수 있습니다 주 스레드에서 너무 많은 일을.
내가 뭘 잘못하고있어 ??
Instagram이 어떤 게시물을 표시하기 위해 어떤 기술을 사용하고 있는지 알고 계십니까? ?
감사
적 데이터로 UI를 만들어 그 변경 지속적으로
당신이 –
@AswinPAshok 이미지 무거운 이미지를로드 할 수 호출하는 또 다른 방법은
AsyncTask
사본을 사용하는 것입니다 단지 15kb-17kb 크기. –
버튼 클릭시 데이터를 가져 오는 중입니까? –