开发者

Trying to have a ListView With diffrent amount of rows

How can a have a ListView that has different amount of rows? Instead of being fixe开发者_C百科d to the array size. I’m loading in information from a html file to a array called Linknames. I then use I then creat a array adapter to link my LinkName array to my ListView. The problem, when I load data into ListView it could be from 1 to 10 colums. So I set my ListVies as anm array with 10 elemtsd. Now my ListView is always 10 elements.

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);
    }
}   


Use an ArrayList instead of a Java array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜