Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2087837
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: 嵌入式

2010-09-09 14:40:47

  1. Docs
    • ListView Background
      http://developer.android.com/resources/articles/listview-backgrounds.html
    • xxx
  2. Adapter
  3. Customize Listview
    • Define and load data
      private String m_rows[] = {"Jimmy", "Jacky", "Lucy", "HanMeimei", "LiLei"}
    • Define layout of row

                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >
                        android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                        android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                                android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                                android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>
         


    • Implement BaseAdapter
      public class MyAdapter extends BaseAdapter { 
          private class ItemViewHolder
          {
              ImageView m_icon;
              TextView m_name;
              TextView m_time;
          }
       
       
          public int getCount()
          {                         
              return m_rows.length;  //Return the count of rows
          } 
       
          public Object getItem(int position)
          {      
              return m_rows[position]; 
          } 
       
          public long getItemId(int position)
          {   
              return position; 
          } 
       
          public View getView(int position, View convertView, ViewGroup parent)
          {  
              ItemViewHolder holder;

              if (convertView == null)
              {
                  convertView = inflater.inflate(R.layout.xxx, null);
                  holder = new ItemViewHolder();
                  holder.m_icon = (ImageView)convertView.findViewById(R.id.icon);
                  holder.m_name = (TextView)convertView.findViewById(R.id.name);
                  holder.m_time = (TextView)convertView.findViewById(R.id.time);
       
                  convertView.setTag(holder);
              }
              else
              {
                  holder = convertView.getTag();
              }   

              holder.m_icon.setImageBitmap(xxx);
              holder.m_name.setText(m_rows[position]);
              holder.m_time.setText(xxx);
         
              return convertView;
          } 
       

    • Display data
      ListView listview = (ListView) findViewById(xxx);
      MyAdapter adapter = new MyAdapter();
      listview.setAdapter(adapter);
    • xxx
  4. Get selected items
    int i, pos;
    SparseBooleanArray array;
    array = listView.getCheckedItemPositions();
    for (i = 0; i < array.size(); i++)
    {
        pos = array.keyAt(i);
        System.out.println("the item " + pos + " is selected");
    }
  5. Long clickable event
    • Add android:longClickable="true" to ListView element of layout file
    • Regieter listener with the following function
      ListView.setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener)
    • xxx
  6. Long clickable Context Menu
    • Add android:longClickable="true" to ListView element of layout file
    • Invoke registerForContextMenu(getListView()) in Activity
    • Override the following functions of Activity
      public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn);
      public boolean onContextItemSelected(MenuItem item)
    • Note:
      • if you called ListView.setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener) for the list view, you must ensure the method onItemLongClick of interface AdapterView.OnItemLongClickListener to return false;
        ie:
        public MyItemLongClickedListener implements AdapterView.OnItemLongClickListener
        {
            public boolean onItemLongClick(AdapterView parent, View view, int position, long id)
            {
                ....
                return false;
            }
        }
      • xxx
    • xxx
  7. Set choice mode
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  8. Seperator View
                style="?android:attr/listSeparatorTextViewStyle"
                android:text="@string/listSeparatorTextViewStyle"
                android:layout_marginTop="5dip"
            />

  9. xxx
阅读(1032) | 评论(0) | 转发(0) |
0

上一篇:[Symbian] Qt for Symbian

下一篇:[Android] Menu

给主人留下些什么吧!~~