[java] view plain copy
class
="language-java">
public
class
myAdapter
extends
BaseAdapter {
- // 獲得當前條目類型
-
public
int
getItemViewType(
int
position) {
- // 如果是標題,返回0
-
if
(position == 0 || position == userAppList.size() + 1) {
-
return
0;
- }
else
{
- // 如果是應用條目,返回1
-
return
1;
- }
- }
- //獲得條目種類個數
- @Override
-
public
int
getViewTypeCount() {
-
return
super
.getViewTypeCount() + 1;
- }
- @Override
- //所有條目總數
-
public
int
getCount() {
-
return
systemAppList.size() + userAppList.size() + 2;
- }
- /*
- * 返回當前條目
- */
-
public
AppInfo getItem(
int
position) {
-
if
(position == 0 || position == userAppList.size() + 1) {
-
return
null
;
- }
else
if
(position < userAppList.size() + 1) {
-
return
userAppList.get(position - 1);
- }
else
{
-
return
systemAppList.get(position - 2 - userAppList.size());
- }
- }
- @Override
-
public
long
getItemId(
int
position) {
-
return
position;
- }
- @Override
-
public
View getView(
int
position, View convertView, ViewGroup parent) {
-
int
type = getItemViewType(position);
- // 如果是純文本
-
if
(type == 0) {
- ViewTitleHolder vth =
null
;
-
if
(convertView ==
null
) {
- convertView = View.inflate(getApplicationContext(),
- R.layout.item_appinfo_title,
null
);
- vth =
new
ViewTitleHolder();
- vth.title = (TextView) convertView
- .findViewById(R.id.tv_appinfo_title);
- convertView.setTag(vth);
- }
else
{
- vth = (ViewTitleHolder) convertView.getTag();
- }
-
if
(position == 0) {
- vth.title.setText("用戶應用(" + userAppList.size() + ")");
- }
else
{
- vth.title.setText("系統應用(" + systemAppList.size() + ")");
- }
-
return
convertView;
- }
else
{
- // 如果是應用介紹
- ViewHolder vh =
null
;
-
if
(convertView ==
null
) {
- convertView = View.inflate(getApplicationContext(),
- R.layout.item_appinfo,
null
);
- vh =
new
ViewHolder();
- vh.icon = (ImageView) convertView
- .findViewById(R.id.iv_appIcon);
- vh.appName = (TextView) convertView
- .findViewById(R.id.tv_appName);
- vh.appIsSdcard = (TextView) convertView
- .findViewById(R.id.tv_appIsSdcard);
- convertView.setTag(vh);
- }
else
{
- vh = (ViewHolder) convertView.getTag();
- }
- AppInfo item = getItem(position);
- vh.icon.setImageDrawable(item.icon);
- vh.appName.setText(item.name);
-
if
(item.isSdcard) {
- vh.appIsSdcard.setText("內存儲卡");
- }
else
{
- vh.appIsSdcard.setText("SdCard應用");
- }
-
return
convertView;
- }
- }
- }
- private ArrayList
systemAppList; //系統應用信息集合 - private ArrayList
userAppList; //用戶應用信息集合
※JSP和Servlet初級知識點總結
※springboot websocket後台主動推送消息
TAG:程序員小新人學習 |