- Why is ListView not scrolling consistently?
- <ListView
- android:id="@+id/list_view"
- android:layout_height="match_parent"
- android:layout_width="match_parent"
- android:scrollingCache="true">
- </ListView>
- adptr = new ArrayAdapter<String>(iF, R.layout.list_item, showing) {
- @Override
- public View getView(int position, View convertView, ViewGroup grp) {
- LinearLayout lin = new LinearLayout(this.getContext());
- lin.setOrientation(LinearLayout.HORIZONTAL);
- // Icon
- ImageView v = new ImageView(this.getContext());
- // v.setBackgroundDrawable(iF.getResources().getDrawable(R.drawable.cube_icon));
- // Text
- TextView txt = new TextView(this.getContext());
- txt.setTextSize(Float.valueOf(prefs.getString("pref_txtSize", "12")));
- txt.setPadding(10, 10, 10, 10);
- txt.setText(this.getItem(position));
- txt.setTextColor(getLineColor(position));
- // Shortcut
- LinearLayout shortLin = new LinearLayout(this.getContext());
- shortLin.setGravity(Gravity.RIGHT);
- LayoutParams par = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- shortLin.setLayoutParams(par);
- TextView s = new TextView(this.getContext());
- s.setTextSize(Float.valueOf(prefs.getString("pref_txtSize", "12")));
- s.setWidth(iF.getResources().getDimensionPixelSize(R.dimen.shortcutWidth));
- s.setPadding(10, 10, 10, 10);
- s.setText(getShortcut(position));
- shortLin.addView(s);
- // Return
- txt.invalidate();
- v.invalidate();
- s.invalidate();
- lin.addView(v);
- lin.addView(txt);
- lin.addView(shortLin);
- return lin;
- }
- };
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = convertView;
- ViewHolder holder;
- if (view == null) {
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater
- .inflate(R.layout.list_view_home_item, parent, false);
- holder = new ViewHolder();
- holder.title = (TextView) view
- .findViewById(R.id.textView);
- holder.title.setText("blah");
- view.setTag(holder);
- } else {
- holder = (ViewHolder) view.getTag();
- }
- return view;
- static class ViewHolder {
- TextView title;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup grp) {
- if(convertView == null) {
- LinearLayout lin = new LinearLayout(this.getContext());
- lin.setOrientation(LinearLayout.HORIZONTAL);
- // Icon
- ImageView v = new ImageView(this.getContext());
- // v.setBackgroundDrawable(iF.getResources().getDrawable(R.drawable.cube_icon));
- // Text
- TextView txt = new TextView(this.getContext());
- txt.setId(1);
- txt.setTextSize(Float.valueOf(prefs.getString("pref_txtSize", "12")));
- txt.setPadding(10, 10, 10, 10);
- txt.setTextColor(getLineColor(position));
- // Shortcut
- LinearLayout shortLin = new LinearLayout(this.getContext());
- shortLin.setGravity(Gravity.RIGHT);
- LayoutParams par = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- shortLin.setLayoutParams(par);
- TextView s = new TextView(this.getContext());
- s.setId(2);
- s.setTextSize(Float.valueOf(prefs.getString("pref_txtSize", "12")));
- s.setWidth(iF.getResources().getDimensionPixelSize(R.dimen.shortcutWidth));
- s.setPadding(10, 10, 10, 10);
- shortLin.addView(s);
- lin.addView(v);
- lin.addView(txt);
- lin.addView(shortLin);
- }
- TextView txt = (TextView)convertView.findViewById(1);
- txt.setText(this.getItem(position));
- TextView txt = (TextView)convertView.findViewById(2);
- txt.setText(getShortcut(position));
- return lin;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = convertView;
- ViewHolder holder;
- if (view == null) {
- LayoutInflater inflater = (LayoutInflater) iF.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.list_item, parent, false);
- holder = new ViewHolder();
- holder.title = (TextView) view.findViewById(R.id.item_text);
- holder.shortcut = (TextView) view.findViewById(R.id.item_short);
- holder.title.setId(1);
- holder.shortcut.setId(2);
- holder.title.setText(getItem((position)));
- holder.shortcut.setText(getShortcut(position));
- holder.title.setTextSize(Float.valueOf(prefs.getString("pref_txtSize", "12")));
- holder.shortcut.setTextSize(Float.valueOf(prefs.getString("prefs_txtSize", "12")));
- view.setTag(holder);
- } else {
- holder = (ViewHolder) view.getTag();
- TextView title = (TextView) convertView.findViewById(1);
- title.setText(getItem(position));
- TextView shortcut = (TextView) convertView.findViewById(2);
- shortcut.setText(getShortcut(position));
- }
- return view;
- }