我在另一个 Activity 类中使用了相同的模式,并且效果很好。但是在这个类(也是一个活动)中,永远不会调用 getView。我通过记录 fbFriendMatchAdapter.getCount() 确认适配器中有 9 个项目。我尝试将数据源更改为 String[] 变量,但这对(缺少)getView 没有影响。
我将不胜感激任何建议!我已经研究得很透彻了。这个问题有多种形式,但没有一个能解决我的问题。这就是为什么我要发布一个新问题。
//Here is the ArrayList data source definition.
//It is loaded using a for loop with 9 values.
private List<String> fbFriendMatchAdapter=new ArrayList<String>();
// Here is the Custom Array Adapter
ArrayAdapter<String> fbFriendMatchAdapter = new ArrayAdapter<String>(this,
R.layout.row_left, R.id.ListViewName, fbFriendPotentialMatchArrayList) {
@Override
public View getView(final int dialogPosition, View convertView, ViewGroup listParent) {
LayoutInflater inflater = getLayoutInflater();
View fbFriendMatchDialogViewRow = inflater.inflate(R.layout.row_left, listParent, false);
Log.d(BBTAG, String.format("BBSetup getView[%s] name=%s", dialogPosition, buddyDisplayName ));
return fbFriendMatchDialogViewRow;
} // [END getView]
@Override
public String getItem(int position) {
return fbFriendPotentialMatchArrayList.get(position);
}
};
//Here is the dialog that includes the ArrayAdapter:
AlertDialog fbFriendsMatchDialog = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.PetesSpinnerReplacement))
.setTitle("Select Correct Facebook Friend") //FYI overridden by custom title
.setAdapter(fbFriendMatchAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedFBFriend) {
buddyFBUIDs[buddyNumber] = fbFriendUIDsList.get(selectedFBFriend);
}
})
.setMessage("No matches found")
.setCancelable(true)
.setPositiveButton("Set as Facebook Friend", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int iFriend) {
dialog.dismiss();
}
})
.setNegativeButton("Friend Not Listed", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
buddyFBUIDs[buddyNumber] = "n/a"; //record lack of FB uid
}
})
.create(); //build dialog
fbFriendsMatchDialog.show(); // now show dialog