我在一个扩展AlertDialog.Builder
的类中有这个构造函数public CustomDialogBuilder(/*Irrelvant args*/)
{
super(context, R.style.AppTheme_Theme_Dialog_Alert);
//...irrelevant init stuff
setTitle("Name");
setPositiveButton("Ok", positiveClick);
setNegativeButton("Not Okay", negativeClick);
this.listView = new ListView();
this.adapter = new CustomListAdapter(listView);
soundsListView.setAdapter(soundsListAdapter);
soundsListView.setItemsCanFocus(true);
soundsListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
soundsListView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
setView(soundsListView);
}
令人费解的是,这导致我在CustomListAdapter中的getView覆盖输出。
Getting view at: 0
Getting view at: 1
Getting view at: 2
Getting view at: 3
Getting view at: 4
Getting view at: 5
Getting view at: 6
Getting view at: 7
Getting view at: 8
Getting view at: 9
Getting view at: 10
Getting view at: 0
Getting view at: 1
Getting view at: 2
Getting view at: 3
Getting view at: 4
Getting view at: 5
Getting view at: 6
Getting view at: 7
Getting view at: 8
Getting view at: 9
Getting view at: 10
Getting view at: 0
Getting view at: 1
Getting view at: 2
Getting view at: 3
Getting view at: 4
Getting view at: 5
Getting view at: 6
Getting view at: 7
Getting view at: 8
Getting view at: 9
Getting view at: 10
20次或更多次。这是一个巨大的瓶颈。构建Dialog时会导致5秒以上的延迟。我不能再使用ViewHolder来优化我的getView方法,除了读取数据库行以获取ViewHolder的值之外,它是一种轻量级方法。
正如您所看到的,我已经将宽度和高度设置为MATCH_PARENT,但无法使用this post建议。
无论如何都要阻止这种过度的呼唤?这是我的应用程序中相当大的瓶颈。