0

我有一个数字数组,我想从最近添加的数字中显示它们,格式如下:数组索引后跟一个冒号,数字以及取决于它是哪个数字,也是这样的感叹号:

10:35, 09:41!, 08:17, 07:5!...

我将如何实现这一目标?

4

1 回答 1

1

它就像一个 ListView...

您需要 SDK 中的 Hello Gridview 示例:http: //developer.android.com/guide/topics/ui/layout/gridview.html

只需将 ImageAdapter 替换为 TextAdapter 即可!

公共类 TextAdapter 扩展 BaseAdapter { 私有上下文 mContext;

public TextAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

public Object getItem(int position) {
    return null;
}

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

// create a new TextView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    TextView textView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        textView = new TextView(mContext);
        textView.setLayoutParams(new GridView.LayoutParams(85, 85));
        textView.setPadding(8, 8, 8, 8);
    } else {
        textView = (TextView) convertView;
    }

    textView.setText(strings[position]);
    return textView;
}

// references to our texts
private String[] strings = {
        "10:35","09:41!","08:17","07:5!",...
};

}

于 2012-12-29T09:09:56.497 回答