我花了几个小时搜索一些关于我的具体问题的有用帖子,但没有成功。
所有帖子都谈到将列表视图布局设置为“fill_parent”。但是我的布局中没有明确的列表视图。
这是代码:
标签适配器:
public class TabsAdapter extends FragmentPagerAdapter implements
TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener, IconPagerAdapter {
.
.
@Override
public Fragment getItem(int position) {
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.clss.getName(),
info.args);
}
.
.
阵列适配器:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(
R.layout.list_activity_segnalazioni_archivio_riga, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.codiceEsterno = (TextView) view
.findViewById(R.id.list_activity_segnalazione_archivio_riga_textview_codice_esterno);
viewHolder.data = (TextView) view
.findViewById(R.id.list_activity_segnalazione_archivio_riga_textview_data);
viewHolder.posizione = (TextView) view
.findViewById(R.id.list_activity_segnalazione_archivio_riga_textview_posizione);
viewHolder.codiceEsterno.setFocusable(false);
viewHolder.codiceEsterno.setFocusableInTouchMode(false);
viewHolder.data.setFocusable(false);
viewHolder.data.setFocusableInTouchMode(false);
viewHolder.posizione.setFocusable(false);
viewHolder.posizione.setFocusableInTouchMode(false);
viewHolder.removeButton = (ImageButton) view.findViewById(R.id.list_activity_segnalazione_archivio_riga_imagebutton_remove);
viewHolder.removeButton.setFocusable(false);
viewHolder.removeButton.setFocusableInTouchMode(false);
viewHolder.previewImage = (ImageView) view
.findViewById(R.id.row_image);
.
.
.
view.setTag(viewHolder);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
try {
holder.codiceEsterno.setText(segnalazioni.get(position).getCodiceEsterno());
holder.data.setText(DateUtils.formatToHumanDate(segnalazioni.get(
position).getDataInizio()));
String address = segnalazioni.get(position).getToponimo();
if (segnalazioni.get(position).getCivico() != null
&& !segnalazioni.get(position).getCivico().equals("")) {
address = address.concat(", ").concat(
segnalazioni.get(position).getCivico().toString()
.toUpperCase(Locale.ITALY));
}
holder.posizione.setText(address);
Map<String, Object> sqlParams = new HashMap<String, Object>();
sqlParams.put("identita", segnalazioni.get(position).getIdStorico());
// This retrieve a base64 image from the sqlite.
// Getting called more times that needed gives me an incredible cpu overhead
**String thumb64 = SegnalamiApplication.abatis.executeForString("getAllFileDatiByIdEntitaForThumb", sqlParams);**
if(thumb64 != null)
{
holder.previewImage.setImageBitmap(BitmapUtils.base64ToBitmap(thumb64));
}
} catch (NullPointerException e) {
e.printStackTrace();
}
return view;
}
xml 布局(与其他 GetItem 帖子最重要的不同之处):
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp" />
<android.support.v4.view.ViewPager
android:id="@+id/archivio_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
此时每个项目被调用 5 次,这给了我一个高开销和少量元素(5 个项目意味着 25 个 GetItem 调用)。
我真诚地希望我们能共同解决这个问题。
如果