所以我一直在使用网格视图来处理我的应用程序中的几个问题,这个问题现在让我烦恼,因为我在大约一周的尝试后无法解决问题。
我正在尝试使用当前存储在多维数组中的时间表填充网格视图,但是填充的唯一索引是第一个。我的BaseAdapter类的副本如下:
package com.ian.calendar.event;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.ian.calendar.database.DatabaseHandler;
import com.ian.campusmap.R;
public class ModuleEvents extends BaseAdapter {
private String weekday;
private Context context;
private View view;
private TextView[] textView;
private DatabaseHandler dbHandler;
private int eventNumber;
private String[][] moduleA;
public ModuleEvents(Context _context, String _weekday) {
context = _context;
weekday = _weekday;
dbHandler = new DatabaseHandler(context);
dbHandler.populateDatabase();
dbHandler.getTimeTable();
}
public int getCount() {
return 6;
}
public View getView(int position, View convertView, ViewGroup parent) {
int i = 1;
eventNumber = getEventsOnWeekday();
moduleA = new String[eventNumber][6];
textView = new TextView[eventNumber];
do {
if(weekday.equals(dbHandler.getTimeTableWeekday(i))) {
for(int j = 0; j < eventNumber; j++) {
moduleA[j][0] = dbHandler.listArray(i, 0);
moduleA[j][1] = dbHandler.listArray(i, 1);
moduleA[j][2] = dbHandler.listArray(i, 3);
moduleA[j][3] = dbHandler.listArray(i, 5);
moduleA[j][4] = dbHandler.listArray(i, 6);
moduleA[j][5] = dbHandler.listArray(i, 2);
i++;
}
} else {
i++;
}
} while(i < dbHandler.count);
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.grid_item_2, null);
}
for(int k = 0; k < moduleA.length; k++) {
textView[k] = new TextView(context);
textView[k] = (TextView) view.findViewById(R.id.txtModuleID);
textView[k].setText(moduleA[k][position]);
}
return view;
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int arg0) {
return 0;
}
public int getEventsOnWeekday() {
int events = 0;
for(int i = 1; i <= 9; i++) {
if(weekday.equals(dbHandler.getTimeTableWeekday(i))) {
events++;
}
}
return events;
}
}
如果您需要任何其他类源代码,请随时询问。
编辑:忘记添加可能有一些冗余代码,我还没有删除。遗憾!
Edit2:摆脱了phtrivier
提到的do / while循环Edit3:我想没有人知道......
答案 0 :(得分:0)
这部分看起来很可疑:
do {
return textView[k];
} while(l < moduleA.length);
如果意味着你的“getView”函数将始终返回第一个TextView,那就是...