need your help with slow scrolling in ListView. When I run my app and scrolling ListView it doing very slow with breaks.
Here's my logcat:
07-07 14:27:17.682 30190-30190/com.nadolskiy.sergey.githubreader I/Choreographer﹕ Skipped 75 frames! The application may be doing too much work on its main thread. 07-07 14:27:22.550 30190-30190/com.nadolskiy.sergey.githubreader I/Choreographer﹕ Skipped 92 frames! The application may be doing too much work on its main thread. 07-07 14:27:30.116 30190-30190/com.nadolskiy.sergey.githubreader I/Choreographer﹕ Skipped 104 frames! The application may be doing too much work on its main thread. 07-07 14:27:32.023 30190-30190/com.nadolskiy.sergey.githubreader I/Choreographer﹕ Skipped 111 frames! The application may be doing too much work on its main thread. 07-07 14:27:33.828 30190-30190/com.nadolskiy.sergey.githubreader I/Choreographer﹕ Skipped 100 frames! The application may be doing too much work on its main thread. custom_listview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="0.2" android:orientation="vertical"> <TextView android:id="@+id/custom_listview_tv_repositoryName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Github-Reader" android:textSize="20dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:id="@+id/custom_listview_tv_languageLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Language: " android:textSize="14dp" /> <TextView android:id="@+id/custom_listview_tv_language" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Java" android:textSize="14dp" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="0.4" android:orientation="horizontal" android:gravity="center"> <TextView android:id="@+id/custom_listview_tv_branchCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="15" android:textSize="20dp" android:layout_weight="0.5" android:gravity="right" /> <ImageView android:id="@+id/custom_listview_iv_branch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_branch" android:layout_weight="0.5" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="0.4" android:orientation="horizontal" android:gravity="center"> <TextView android:id="@+id/custom_listview_tv_inFavoriteCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="31" android:textSize="20dp" android:layout_weight="0.5" android:gravity="right" /> <ImageView android:id="@+id/custom_listview_iv_favorite" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_star" android:layout_weight="0.5" /> </LinearLayout> </LinearLayout> CustomAdapter.java
public class CustomAdapter extends BaseAdapter implements DialogInterface.OnClickListener { private Activity activity; private ArrayList data; private static LayoutInflater inflater = null; public Resources res; ListModel tempValues = null; int i = 0; Typeface textFont; public CustomAdapter(Activity a, ArrayList d, Resources resLocal) { activity = a; data = d; res = resLocal; textFont = Typeface.createFromAsset(activity.getAssets(), "fonts/DiamondGirl.ttf"); inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { if (data.size() <= 0) return 1; return data.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } public static class ViewHolder { public TextView repositoryName; public TextView language; public TextView branchCount; public TextView inFavoriteCount; } @Override public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView; ViewHolder holder; if (convertView == null) { vi = inflater.inflate(R.layout.custom_listview, null); holder = new ViewHolder(); holder.repositoryName = (TextView) vi.findViewById( R.id.custom_listview_tv_repositoryName); holder.language = (TextView) vi.findViewById( R.id.custom_listview_tv_language); holder.branchCount = (TextView) vi.findViewById( R.id.custom_listview_tv_branchCount); holder.inFavoriteCount = (TextView) vi.findViewById( R.id.custom_listview_tv_inFavoriteCount); vi.setTag(holder); } else { holder = (ViewHolder) vi.getTag(); } ; if (data.size() <= 0) { holder.repositoryName.setText("No Data"); } else { tempValues = null; tempValues = (ListModel) data.get(position); holder.repositoryName.setText(tempValues.getRepositoryName()); holder.language.setText(tempValues.getLanguage()); holder.branchCount.setText(tempValues.getBranchCount()); holder.inFavoriteCount.setText(tempValues.getInFavoriteCount()); vi.setOnClickListener(new OnItemClickListener(position)); } holder.repositoryName.setTypeface(textFont); holder.language.setTypeface(textFont); holder.branchCount.setTypeface(textFont); holder.inFavoriteCount.setTypeface(textFont); return vi; } @Override public void onClick(DialogInterface dialog, int which) { Log.v("Custom Adapter", "Button Clicked"); } private class OnItemClickListener implements View.OnClickListener { private int mPosition; OnItemClickListener(int position) { mPosition = position; } @Override public void onClick(View v) { UserActivity ua = (UserActivity) activity; ua.onItemClick(mPosition); } } ListModel.java
public class ListModel { private String repositoryName = ""; private String language = ""; private String branchCount = ""; private String inFavoriteCount = ""; public void setRepositoryName(String repositoryName) { this.repositoryName = repositoryName; } public void setLanguage(String language) { this.language = language; } public void setBranchCount(String branchCount) { this.branchCount = branchCount; } public void setInFavoriteCount(String inFavoriteCount) { this.inFavoriteCount = inFavoriteCount; } public String getRepositoryName() { return repositoryName; } public String getLanguage() { return language; } public String getBranchCount() { return branchCount; } public String getInFavoriteCount() { return inFavoriteCount; } } UserActivity.java
public class UserActivity extends AppCompatActivity { ListView list; CustomAdapter adapter; public UserActivity userActivity = null; public ArrayList<ListModel> customListViewValuesArr = new ArrayList<ListModel>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user); userActivity = this; setListData(); Resources res = getResources(); list = (ListView) findViewById(R.id.activitu_user_lv_repositoriesList); adapter = new CustomAdapter(userActivity, customListViewValuesArr, res); list.setAdapter(adapter); } private void setListData() { for (int i = 0; i < 11; i++) { final ListModel sched = new ListModel(); sched.setRepositoryName("Repository №" + i); sched.setLanguage("Java"); sched.setBranchCount("" + (i+5)); sched.setInFavoriteCount("" + (i*12)); customListViewValuesArr.add(sched); } } public void onItemClick(int mPosition) { ListModel tempValues = (ListModel) customListViewValuesArr.get(mPosition); Toast.makeText(userActivity, "" + tempValues.getRepositoryName(), Toast.LENGTH_LONG).show(); } } Thanks, =)