当前位置:操作系统 > 安卓/Android >>

android Gridview生成程序快捷键的复杂方法

 本章跟上篇文章的区别在于我的通讯录图标上增加显示了有多少联系人。
mainpage.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
   
 <GridView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/gridview"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" 
    android:padding="10dp" 
    android:verticalSpacing="10dp" 
     
    android:horizontalSpacing="10dp" 
    android:numColumns="auto_fit" 
    android:columnWidth="60dp" 
    android:stretchMode="columnWidth" 
     
    android:gravity="center" 
    />   
 
MainPageActivity
package Cloud.Android.ERP;

import java.util.ArrayList;
import java.util.HashMap;


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MainPageActivity extends InternalBaseActivity {
   
   

 
   
    String[]  strTitle={"我的通讯录","我的课表" };
    HashMap<String, Object> DrawalleMap;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainpage);
      
        createShutCut();
       

    }
   
    //生成快捷键
    void createShutCut()
    {
         GridView  gridview = (GridView) findViewById(R.id.gridview); 
          DrawalleMap = new HashMap<String, Object>(); 
          DrawalleMap.put("我的通讯录", R.drawable.inco_1 );//添加图像资源的ID 
          DrawalleMap.put("我的课表",  R.drawable.inco_5  );
        
        
        gridview.setAdapter(new ImageAdapter(this)); 
        gridview.setOnItemClickListener(new ItemClickListener());
    }
    public class ImageAdapter extends BaseAdapter { 
        private Context mContext; 
        public ImageAdapter(Context c) { 
            mContext = c; 
        } 
     
        public int getCount() { 
            return strTitle.length; 
        } 
     
        public Object getItem(int position) { 
            return position; 
        } 
     
        public long getItemId(int position) { 
            return position; 
        } 
      
        public View getView(int position, View convertView, ViewGroup parent) { 
           
            ItemViewCache viewCache;
            
            viewCache = new ItemViewCache();
                        convertView = LayoutInflater.from(MainPageActivity.this)
                        .inflate(R.layout.icon_item, null);
                viewCache.txttasktitle = (TextView) convertView
                        .findViewById(R.id.ItemText);


                viewCache.imageView = (ImageView) convertView
                .findViewById(R.id.ItemImage);
   
                viewCache.txttasktitle.setText(strTitle[position]);
                if (DrawalleMap.containsKey(strTitle[position].trim()))
                {
  &nb

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,