我想画一个表格,用到了listview,参考的例子是这里:http://blog.csdn.net/hellogv/archive/2010/12/14/6075014.aspx
有两个文件:一个是Mylistview.java和TableAdapter.java,但是出现了错误(红色字体),麻烦大家帮下忙!!谢谢!!public class Mylistview extends Activity {
    /** Called when the activity is first created. */
    ListView listview;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.setTitle("课程表");
        listview=(ListView)findViewById(R.id.listview1);
        ArrayList<TableRow> table=new ArrayList<TableRow>();
        TableCell[] title=new TableCell[6];
        int width=this.getWindowManager().getDefaultDisplay().getWidth()/title.length;
       
        title[0]=new TableCell("时间",width*8,LayoutParams.FILL_PARENT);
        title[1]=new TableCell("星期一",width*8,LayoutParams.FILL_PARENT);
        title[2]=new TableCell("星期二",width*8,LayoutParams.FILL_PARENT);
        title[3]=new TableCell("星期三",width*8,LayoutParams.FILL_PARENT);
        title[4]=new TableCell("星期四",width*8,LayoutParams.FILL_PARENT);
        title[5]=new TableCell("星期五",width*8,LayoutParams.FILL_PARENT);
        
        table.add(new TableRow(title));        
        TableCell cell1[]=new TableCell[6];
        
        cell1[0]=new TableCell("第一二节",width*8,LayoutParams.FILL_PARENT);
        cell1[3]=new TableCell("大学物理(第1-19周) 芦明霞  二教阶梯 D307",width*8,LayoutParams.FILL_PARENT);
        cell1[4]=new TableCell("大学英语(第1-18周)单周 杨莉  一教小教A308",width*8,LayoutParams.FILL_PARENT);
        
       
        
         table.add(new TableRow(cell1));        TableAdapter tableAdapter=new TableAdapter(this,table);        listview.setAdapter(tableAdapter);
             
    }
}
public class TableAdapter extends BaseAdapter{
private Context context;
private List<TableRow> table;
public TableAdapter(Context context,List<TableRow> table)
{
this.context=context;
this.table=table;
} public int getCount()
{
return table.size();
}

public long getItemId(int position)
{
return position;
}

public TableRow getItem(int position)
{
return table.get(position);
}
public View getView(int position,View convertView,ViewGroup parent)
{
TableRow tableRow=table.get(position);
return new TableRowView(this.context,tableRow);
}




class TableRowView extends LinearLayout{
public TableRowView(Context context,TableRow tableRow)
{
super(context);
this.setOrientation(LinearLayout.HORIZONTAL);
for(int i=0;i<tableRow.getSize();i++)
{
TableCell tableCell=tableRow.getCellValue(i);
LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(tableCell.width,tableCell.height);
layoutParams.setMargins(0,0,1,1);
TextView textCell=new TextView(context);
textCell.setLines(1);
textCell.setGravity(Gravity.CENTER);
textCell.setBackgroundColor(Color.WHITE);
textCell.setText(String.valueOf(tableCell.value));
addView(textCell,layoutParams);
}
this.setBackgroundColor(Color.WHITE);
}

}


static public class TableRow{
private TableCell[] cell;
public TableRow(TableCell cell[]){
this.cell=cell;

}
public int getSize(){
return cell.length;
}
public TableCell getCellValue(int index){
if(index>=cell.length)
return null;
return cell[index];
}

} static public class TableCell{
public String value;
public int width;
public int height;

public TableCell(String value,int width,int height){
this.value=value;
this.width=width;
this.height=height;

} }
}

解决方案 »

  1.   

    你传的参数都是新NEW的 所以都是空的. 我是这样认为的
      

  2.   

    提示说:“The constructor TableRow(TableAdapter.TableCell[]) is undefined”
    "The constructor TableAdapter(Mylistview, ArrayList<TableRow>) is undefined“
    说没构造函数,但是明明TableAdapter.java里面已经定义了!
      

  3.   

    我把你的代码复制了一下 发现了这个问题
     TableRow 是系统自带的一个类 你自己又写了一个 构造函数参数是Context  而你用的table.add(new TableRow(title));  不正确
    希望对你有所帮助
      

  4.   

    恩,哈哈,楼上说得对..昨天我同学也告诉我要加上
    import com.example.android.schedule.TableAdapter.TableRow;
    怎么给分你,我没分..我到现在都不知道怎么获取分数,能用钱买吗?