2011-03-31 19 views
0

如何使用具有不同數量的行的ListView?而不是被固定到數組大小。 我正在從html文件加載信息到一個名爲Linknames的數組。然後我使用我然後創建一個數組適配器鏈接我的LinkName數組到我的ListView。 問題是,當我將數據加載到ListView時,它可能會從1到10列。所以我將我的ListVies設置爲10個elemtsd的anm數組。現在我的ListView總是10個元素。嘗試使用不同數量的行的ListView

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // data read in can be from 1-10 
    images=new String[10]; 
    Links=new String[10]; 
    LinkName=new String[10]; 
    Price=new String[10]; 

Loaddata();  

setListAdapter(new IconicAdapter(this)); 
} // end function 

class IconicAdapter extends ArrayAdapter { 
    Activity context; 

    IconicAdapter(Activity context) { 
     super(context, R.layout.row, LinkName); 

     this.context=context; 
    } 

    public View getView(int position, View convertView, 
              ViewGroup parent) { 
     LayoutInflater inflater=context.getLayoutInflater(); 
     View row=inflater.inflate(R.layout.row, null); 
     TextView label=(TextView)row.findViewById(R.id.label); 

     label.setText(LinkName[position]); 
     return(row); 
    } 
} 

回答

相關問題