package com.mark;
import java.lang.reflect.Field;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
/**
* @author Sodino E-mail:sodinoopen@hotmail.com
* @version Time:2011-5-1 下午03:22:00
*/
public class MainActivity extends Activity implements ListView.OnScrollListener, OnItemClickListener,
android.view.View.OnClickListener {
private Handler handler;
private DisapearThread disapearThread;
/** 标识List的滚动状态。 */
private int scrollState;
private ListAdapter listAdapter;
private ListView listMain;
private TextView txtOverlay;
private WindowManager windowManager;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler = new Handler();
// 初始化首字母悬浮提示框
txtOverlay = (TextView) LayoutInflater.from(this).inflate(R.layout.popup_char_hint, null);
txtOverlay.setVisibility(View.INVISIBLE);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(txtOverlay, lp);
// 初始化ListAdapter
listAdapter = new ListAdapter(this, stringArr, this);
listMain = (ListView) findViewById(R.id.listInfo);
listMain.setOnItemClickListener(this);
listMain.setOnScrollListener(this);
listMain.setAdapter(listAdapter);
changeFastScrollerDrawable(listMain);
disapearThread = new DisapearThread();
}
/** 更改指定ListView的快速滚动条图标。 */
private void changeFastScrollerDrawable(ListView list) {
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object obj = f.get(list);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(obj);
drawable = getResources().getDrawable(R.drawable.fast_scroller_img);
f.set(obj, drawable);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/** ListView.OnScrollListener */
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
// 以中间的ListItem为标准项。
txtOverlay.setText(String.valueOf(stringArr[firstVisibleItem + (visibleItemCount >> 1)]
.charAt(0)));
}
/** ListView.OnScrollListener */
public void onScrollStateChanged(AbsListView view, int scrollState) {
this.scrollState = scrollState;
if (scrollState == ListView.OnScrollListener.SCROLL_STATE_IDLE) {
handler.removeCallbacks(disapearThread);
// 提示延迟1.5s再消失
boolean bool = handler.postDelayed(disapearThread, 1500);
Log.d("ANDROID_INFO", "postDelayed=" + bool);
} else {
txtOverlay.setVisibility(View.VISIBLE);
}
}
/** OnItemClickListener */
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String personalName = stringArr[position];
String url = ListAdapter.URL_PREFIX + personalName.replace(" ", "%20");
showInfo(personalName, url);
}
/**
* View.OnClickListener <br/>
* 点击“咧牙”图片。<br/>
*/
public void onClick(View view) {
if (view instanceof ImageView) {
// "咧牙"图标
int position = ((Integer) view.getTag()).intValue();
ActionItem actionAdd = new ActionItem(getResources().getDrawable(R.drawable.icon_info),
"Info", this);
ActionItem actionWeb = new ActionItem(getResources().getDrawable(R.drawable.icon_web),
"Web", this);
ActionItem actionEMail = new ActionItem(getResources().getDrawable(
R.drawable.icon_email), "Email", this);
QuickActionBar qaBar = new QuickActionBar(view, position);
qaBar.setEnableActionsLayoutAnim(true);
qaBar.addActionItem(actionAdd);
qaBar.addActionItem(actionWeb);
qaBar.addActionItem(actionEMail);
qaBar.show();
} else if (view instanceof LinearLayout) {
// ActionItem组件
LinearLayout actionsLayout = (LinearLayout) view;
QuickActionBar bar = (QuickActionBar) actionsLayout.getTag();
bar.dismissQuickActionBar();
int listItemIdx = bar.getListItemIndex();
TextView txtView = (TextView) actionsLayout.findViewById(R.id.qa_actionItem_name);
String actionName = txtView.getText().toString();
String personalName = stringArr[listItemIdx];
String url = ListAdapter.URL_PREFIX + personalName.replace(" ", "%20");
if (actionName.equals("Info")) {
showInfo(personalName, url);
} else if (actionName.equals("Web")) {
go2Web(url);
} else if (actionName.equals("Email")) {
sendEMail(personalName, url);
}
}
}
public void showInfo(String name, String url) {
String content = "Name:" + name + "\n"//
+ "URL:" + url//
;
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.info_dialog);
dialog.setTitle("Personal Information");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(content);
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon_info);
dialog.show();
}
private void go2Web(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
private void sendEMail(String name, String url) {
Intent mailIntent = new Intent(Intent.ACTION_SEND);
// 设置邮件类型为纯文本,即为所有可见字符与一些简单的控制符的组合。
mailIntent.setType("plain/text");
// 收件人地址
String[] arrReceiver = { "sodinoopen@hotmail.com" };
// 抄送地址
String[] arrCc = { "sodinoopen@hotmail.com" };
// 密送地址
String[] arrBcc = { "sodinoopen@hotmail.com", "sodinoopen@hotmail.com" };
String mailSubject = "This is a mail send by list demo";
String mailBody = "Hello everyone, I think the my demo is very good, haha. thanks.";
// 指定要添加的附件的完整路径
String attachPath = "file:///sdcard/Test.apk";
mailIntent.putExtra(Intent.EXTRA_EMAIL, arrReceiver);
mailIntent.putExtra(Intent.EXTRA_CC, arrCc);
mailIntent.putExtra(Intent.EXTRA_BCC, arrBcc);
mailIntent.putExtra(Intent.EXTRA_SUBJECT, mailSubject);
mailIntent.putExtra(Intent.EXTRA_TEXT, mailBody);
mailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachPath));
// 过滤Intent并启动GMail界面,之后点击Send即可将邮件发送出去。
Intent finalIntent = Intent.createChooser(mailIntent, "Mail Sending...");
startActivity(finalIntent);
}
private class DisapearThread implements Runnable {
public void run() {
// 避免在1.5s内,用户再次拖动时提示框又执行隐藏命令。
if (scrollState == ListView.OnScrollListener.SCROLL_STATE_IDLE) {
txtOverlay.setVisibility(View.INVISIBLE);
}
}
}
public void onDestroy() {
super.onDestroy();
// 将txtOverlay删除。
txtOverlay.setVisibility(View.INVISIBLE);
windowManager.removeView(txtOverlay);
}
private String[] stringArr = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
"Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu",
"Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Alverca",
没有合适的资源?快使用搜索试试~ 我知道了~
滑动显示首字母的ListView
共88个文件
xml:39个
png:19个
class:18个
4星 · 超过85%的资源 需积分: 3 81 下载量 40 浏览量
2012-01-15
00:37:03
上传
评论
收藏 265KB RAR 举报
温馨提示
以前在网上找了一个例子挺好好的,一直没有有时间和大家分享一下,申明不是原创。 例子是滑动listView的时候同时显示item首字母。
资源推荐
资源详情
资源评论
收起资源包目录
滑动显示首字母的ListView.rar (88个子文件)
ComplexListDemo
AndroidManifest.xml 674B
anim
bar_show_from_top.xml 507B
bar_show_from_topleft_to_bottomright.xml 506B
bar_show_from_bottom.xml 791B
bar_hide_from_topright_to_bottomleft.xml 508B
bar_hide_from_bottomleft_to_topright.xml 520B
anim_actionslayout.xml 686B
bar_show_from_topright_to_bottomleft.xml 520B
bar_hide_from_topleft_to_bottomright.xml 522B
bar_show_from_bottomleft_to_topright.xml 506B
bar_hide_from_bottomright_to_topleft.xml 506B
bar_hide_from_bottom.xml 507B
bar_hide_from_top.xml 509B
bar_show_from_bottomright_to_topleft.xml 521B
res
anim
bar_show_from_top.xml 507B
bar_show_from_topleft_to_bottomright.xml 506B
bar_show_from_bottom.xml 791B
bar_hide_from_topright_to_bottomleft.xml 508B
bar_hide_from_bottomleft_to_topright.xml 520B
anim_actionslayout.xml 686B
bar_show_from_topright_to_bottomleft.xml 520B
bar_hide_from_topleft_to_bottomright.xml 522B
bar_show_from_bottomleft_to_topright.xml 506B
bar_hide_from_bottomright_to_topleft.xml 506B
bar_hide_from_bottom.xml 507B
bar_hide_from_top.xml 509B
bar_show_from_bottomright_to_topleft.xml 521B
layout
info_dialog.xml 628B
action_item.xml 1KB
popup_char_hint.xml 389B
qa_bar.xml 2KB
list_item.xml 3KB
main.xml 1KB
drawable-ldpi
icon.png 2KB
drawable-mdpi
icon_info.png 6KB
main_list_bg.jpg 303KB
person.png 15KB
qa_border_top.9.png 313B
qa_arrow_up.png 320B
pressed.png 154B
icon_web.png 6KB
qa_btn_pressed.9.png 273B
qa_anchor_btn_bg.xml 422B
qa_slider_left.png 752B
qa_border_bottom.9.png 318B
qa_actionitem_bg.xml 954B
qa_arrow_down.png 326B
qa_bar_background.png 968B
qa_btn_normal.9.png 420B
icon.png 20KB
fast_scroller_img.png 2KB
qa_slider_right.png 779B
qa_btn_focused.9.png 292B
icon_email.png 5KB
drawable-hdpi
icon.png 4KB
values
dimension.xml 714B
strings.xml 183B
colors.xml 168B
styles.xml 2KB
proguard.cfg 1KB
src
com
mark
MainActivity.java 18KB
QuickActionBar.java 10KB
ListAdapter.java 3KB
ActionItem.java 662B
CustomInterpolator.java 1KB
bin
classes
com
mark
QuickActionBar.class 8KB
R$color.class 414B
ListAdapter.class 3KB
ListAdapter$ViewHolder.class 629B
R.class 611B
ActionItem.class 1KB
MainActivity.class 27KB
R$anim.class 1022B
CustomInterpolator.class 786B
R$layout.class 536B
R$attr.class 310B
R$style.class 767B
R$id.class 1KB
R$string.class 397B
MainActivity$DisapearThread.class 929B
QuickActionBar$1.class 1KB
R$dimen.class 906B
R$drawable.class 1KB
res
.classpath 288B
assets
project.properties 360B
.settings
org.eclipse.core.resources.prefs 110B
.project 851B
gen
com
mark
R.java 6KB
共 88 条
- 1
Harlan
- 粉丝: 15
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页