如何制作包含数组的listview?

时间:2014-08-09 10:03:40

标签: java android arrays listview bitmap

我希望制作一个数组列表视图,但我似乎无法让它工作,你可以看到我的代码有点失落。我试图让我的列表视图包含Bitmap[]String[]double[],但根据我的代码和日食我不能这样做...我必须将它们转换为普通的botmaps,字符串和双打,这将需要4ever。

ConnectMySQL是我连接数据库并检索信息的地方。我在我的数组中存储了100个不同的东西(位图,字符串,双精度)。所有内容都以[]格式存储在位图中,或者它存储在名为ArrayList<Bitmap>的内容中,但是我将其转换为Bitmap[]。但是如何将数组放入listview?

public class LVFinal extends Activity{
ArrayList<Bitmap> aMaster;
    Bitmap[] bitmapArray;
    String[] sMaster;
    Double[] dMaster;
    double[] doubleArray;

    private List<LVSecond> myList = new ArrayList<LVSecond>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        aMaster = ConnectMySQL.getRankingPic();
        sMaster = ConnectMySQL.getName();
        dMaster = ConnectMySQL.getRank();
        //stringRet(); //same as below pretty much, ignore this!
        bitmapReturn(); //this will return a1, a2, a3 and so on, but in normal bitmap(s) so i can use it in my code for custom listview
        doubleReturn(); // same as above pretty much
        populatePicture();
        populateListView();
    }


    private void doubleReturn() {
        // TODO Auto-generated method stub
        doubleArray = new double[dMaster.length];
        for(int k = 0; k < doubleArray.length; k++) {
            doubleArray[k] = (double) dMaster[k];
        }
    }


    /*private void stringRet() {
        // TODO Auto-generated method stub

    }*/


    private void bitmapReturn() {
        // TODO Auto-generated method stub
        bitmapArray = new Bitmap[aMaster.size()];
        bitmapArray = aMaster.toArray(bitmapArray);
    }


    private void populatePicture() {
        // TODO Auto-generated method stub
        myList.add(new LVSecond(sMaster, bitmapArray, doubleArray));

    }

    private void populateListView() {
        // TODO Auto-generated method stub
        ArrayAdapter<LVSecond> adapter = new MyListAdapter();
        ListView list = (ListView) findViewById(R.id.lvRanking);
        list.setAdapter(adapter);
    }

    private class MyListAdapter extends ArrayAdapter<LVSecond>{
        public MyListAdapter() {
            super(LVFinal.this, R.layout.item_list, myList);
        }

        /* (non-Javadoc)
         * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
         */
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View itemView = convertView;
            if (itemView == null) {
                itemView = getLayoutInflater().inflate(R.layout.item_list, parent, false);
            }
            // Find the list to work with
            LVSecond currentList = myList.get(position);

            // Fill the view, picture
            ImageView imageView = (ImageView)itemView.findViewById(R.id.item_iv);
            imageView.setImageBitmap(currentList.getIconPic());;

            // Fill the name, persons name
            TextView name = (TextView) itemView.findViewById(R.id.item_tvName);
            name.setText(currentList.getName());

            // Fill the score
            TextView rank = (TextView) itemView.findViewById(R.id.item_tvScore);
            rank.set;

            return itemView;
            //return super.getView(position, convertView, parent);
        }


    }
}


public class LVSecond {
private String[] name;
private Bitmap[] iconPic;
private double[] ranking;

public LVSecond(String[] name, Bitmap[] bitmapArray, double[] getRanking){
    super();
    this.name = name;
    this.iconPic = bitmapArray;
    this.ranking = getRanking;

}

public String[] getName() {
    return name;
}
public Bitmap[] getIconPic() {
    return iconPic;
}
public double[] getRanking() {
    return ranking;
}

}

0 个答案:

没有答案