我已经创建了自己的ArrayAdapter但是我遇到了getView方法的问题 - 它从未被调用过。我的Logcat只显示构造函数的日志,而不是getView。我已经尝试过更改为BaseAdapter并尝试重写getCount但没有运气,getView将不会被调用。我已经确保传入的列表不是空的,但仍然没有运气。这是我的代码:
public class ProgramSelectionSchoolAdapter extends ArrayAdapter<String> {
private ArrayList<String> schools;
private Activity context;
private static final String TAG = "ProgSelSchoolAdapter";
public ProgramSelectionSchoolAdapter(Activity context, ArrayList<String> schools) {
super(context, R.layout.spinner_program_selection_row, schools);
this.schools = schools;
this.context = context;
Log.v(TAG, "ProgramSelectionSchoolAdapter was created");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
Log.v(TAG, "getView was called");
ViewHolder holder;
if (rowView == null) {
holder = new ViewHolder();
// Inflate the row layout
LayoutInflater inflater = LayoutInflater.from(context);
rowView = inflater.inflate(R.layout.spinner_program_selection_row, parent, false);
// Use of view holder to save performance
holder.spinnerItem = (TextView) rowView.findViewById(R.id.tvSpinnerItem);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
// Set the text for the view holder
String school = schools.get(position);
holder.spinnerItem.setText(school);
Log.v(TAG, school + " added to spinnerItem");
return rowView;
}
static class ViewHolder {
public TextView spinnerItem;
}
}
以下是我如何使用适配器:
private void setUpSpinner() {
// Construct a list to be used for storing unique school values for the adapter
schools = new ArrayList<String>();
// Query for all organizers
ParseQuery<Organizer> query = ParseQuery.getQuery(Organizer.class);
query.whereEqualTo(COLUMN_APP, APP_NAME);
query.orderByAscending(COLUMN_SCHOOL);
query.findInBackground(new FindCallback<Organizer>() {
@Override
public void done(List<Organizer> organizers, ParseException e) {
if(e == null) {
// All organizers for the chosen app was received successfully
Log.v(TAG, "Organizers received successfully");
// Go through all organizers and look for unique school values
for (Organizer organizer : organizers) {
String school = organizer.getSchool();
if(!schools.contains(school)) {
// Add the unique school to the ArrayList
schools.add(school);
Log.v(TAG, school + " added to list");
}
}
// Create the adapter for the schools
adapterSchools = new ProgramSelectionSchoolAdapter(ProgramSelection.this, schools);
} else {
// Something went wrong
e.printStackTrace();
}
}
});
// Create spinner and set adapter
spinnerPrograms = (Spinner) findViewById(R.id.spinnerPrograms);
spinnerPrograms.setAdapter(adapterSchools);
}
我正在为应用程序中的另一个活动使用类似的适配器,那个工作正常。我错过了什么?任何帮助表示赞赏!
答案 0 :(得分:0)
当*/5 * * * * wget -q localhost:8888/example/index.php/controller/function
为空时,您正在呼叫spinnerPrograms.setAdapter(adapterSchools);
。虽然看起来您正在将变量设置为新的ProgramSelectionSchoolAdapter,但直到后台任务完成后才会实际调用该代码。尝试使用adapterSchools
方法调用setAdapter。