android字母索引
㈠ android中如何对单词进行首字母排序 按A到Z的顺序。
- 点击工具栏中的“排序”按钮;
- “主要关键字”选择段落,“类型”选择拼音;
㈡ 安卓的英文缩写是什么
英文单词“Android”就是安卓的英文缩写。其实是英译过来的中文名称。
android是一种以Linux与java为基础的开放源代码操作系统,主要使用于便携设备。中国大陆地区较多人使用“安卓”。
㈢ jq怎么实现listview的a-z字母排序和过滤搜索功能
按照项目中类的顺序来一一介绍其功能
1.SortModel 一个实体类,里面一个是ListView的name,另一个就是显示的name拼音的首字母
[java] view plain
package com.example.sortlistview;
public class SortModel {
private String name; //显示的数据
private String sortLetters; //显示数据拼音的首字母
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSortLetters() {
return sortLetters;
}
public void setSortLetters(String sortLetters) {
this.sortLetters = sortLetters;
}
}
2.SideBar类就是ListView右侧的字母索引View,我们需要使用setTextView(TextView mTextDialog)来设置用来显示当前按下的字母的TextView,以及使用方法来设置回调接口,在回调方法onTouchingLetterChanged(String s)中来处理不同的操作
[java] view plain
package com.example.sortlistview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
public class SideBar extends View {
// 触摸事件
private ;
// 26个字母
public static String[] b = { "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "#" };
private int choose = -1;// 选中
private Paint paint = new Paint();
private TextView mTextDialog;
/**
* 为SideBar设置显示字母的TextView
* @param mTextDialog
*/
public void setTextView(TextView mTextDialog) {
this.mTextDialog = mTextDialog;
}
public SideBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SideBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SideBar(Context context) {
super(context);
}
/**
* 重写这个方法
*/
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 获取焦点改变背景颜色.
int height = getHeight();// 获取对应高度
int width = getWidth(); // 获取对应宽度
int singleHeight = height / b.length;// 获取每一个字母的高度
for (int i = 0; i < b.length; i++) {
paint.setColor(Color.rgb(33, 65, 98));
// paint.setColor(Color.WHITE);
paint.setTypeface(Typeface.DEFAULT_BOLD);
paint.setAntiAlias(true);
paint.setTextSize(20);
// 选中的状态
if (i == choose) {
paint.setColor(Color.parseColor("#3399ff"));
paint.setFakeBoldText(true);
}
// x坐标等于中间-字符串宽度的一半.
float xPos = width / 2 - paint.measureText(b[i]) / 2;
float yPos = singleHeight * i + singleHeight;
canvas.drawText(b[i], xPos, yPos, paint);
paint.reset();// 重置画笔
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
final int action = event.getAction();
final float y = event.getY();// 点击y坐标
final int oldChoose = choose;
final listener = ;
final int c = (int) (y / getHeight() * b.length);// 点击y坐标所占总高度的比例*b数组的长度就等于点击b中的个数.
switch (action) {
case MotionEvent.ACTION_UP:
setBackgroundDrawable(new ColorDrawable(0x00000000));
choose = -1;//
invalidate();
if (mTextDialog != null) {
mTextDialog.setVisibility(View.INVISIBLE);
}
break;
default:
setBackgroundResource(R.drawable.sidebar_background);
if (oldChoose != c) {
if (c >= 0 && c < b.length) {
if (listener != null) {
listener.onTouchingLetterChanged(b[c]);
}
if (mTextDialog != null) {
mTextDialog.setText(b[c]);
mTextDialog.setVisibility(View.VISIBLE);
}
choose = c;
invalidate();
}
}
break;
}
return true;
}
/**
* 向外公开的方法
*
* @param
*/
public void (
) {
this. = ;
}
/**
* 接口
*
* @author coder
*
*/
public interface {
public void onTouchingLetterChanged(String s);
}
}
㈣ android textview怎么获取指定坐标的字符索引
获取textview字符串,通过字符串的函数获取。
㈤ Android自定义字母导航栏
自定义侧边字母导航栏,根据实际字母高度进行显示
先上效果图
public class SlideBar extends View {
//当前手指滑动到的位置
private int choosedPosition = -1;
//画文字的画笔
private Paint paint;
//单个字母的高度
private float perTextHeight;
//字母的字体大小
private float letterSize;
//字母的垂直间距
private float letterGap;
//字母圆形背景半径
private float bgRadius;
private ArrayList<String> firstLetters = new ArrayList<>();
//绘制点击时的蓝色背景
private Paint backgroundPaint;
private Context context;
private OnTouchFirstListener listener;
public RecyclerView getTiku_recycle_answer() {
return tiku_recycle_answer;
}
public void setTiku_recycle_answer(RecyclerView tiku_recycle_answer) {
this.tiku_recycle_answer = tiku_recycle_answer;
}
RecyclerView tiku_recycle_answer;
public SlideBar(Context context) {
this(context, null);
}
public SlideBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SlideBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SlideBar);
//字母的字体大小
letterSize = typedArray.getDimension(R.styleable.SlideBar_letter_size, DisplayUtils.sp2px(context, 10.0f));
//每个字母的高
perTextHeight = typedArray.getDimension(R.styleable.SlideBar_letter_height, DisplayUtils.dp2px(context, 10.0f));
//字母垂直间距
letterGap = typedArray.getDimension(R.styleable.SlideBar_letter_gap, DisplayUtils.dp2px(context, 6.0f));
//字母垂直间距
bgRadius = typedArray.getDimension(R.styleable.SlideBar_letter_bg_radius, DisplayUtils.dp2px(context, 8.0f));
typedArray.recycle();
init();
}
public void init() {
//初始化画笔
paint = new Paint();
paint.setAntiAlias(true);
paint.setTextSize(letterSize);
paint.setTypeface(Typeface.DEFAULT_BOLD);
//初始化圆形背景画笔
backgroundPaint = new Paint();
backgroundPaint.setAntiAlias(true);
backgroundPaint.setColor(context.getResources().getColor(R.color.color_368FFF));
}
public void setFirstLetters(ArrayList<String> letters) {
firstLetters.clear();
firstLetters.addAll(letters);
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec); //获取宽的模式
int heightMode = MeasureSpec.getMode(heightMeasureSpec); //获取高的模式
int widthSize = MeasureSpec.getSize(widthMeasureSpec); //获取宽的尺寸
int heightSize = MeasureSpec.getSize(heightMeasureSpec); //获取高的尺寸
int width = 0;
int height;
if (widthMode == MeasureSpec.EXACTLY) {
//如果match_parent或者具体的值,直接赋值
width = widthSize;
} else {
//如果其他模式,则指定一个宽度
width = DisplayUtils.dp2px(getContext(), 20.0f);
}
//高度跟宽度处理方式一样
if (heightMode == MeasureSpec.EXACTLY) {
height = heightSize;
} else {
float textHeight = perTextHeight;
height = (int) (getPaddingTop() + textHeight * (firstLetters.size() + 1) + letterGap * (firstLetters.size() - 1) + getPaddingBottom());
}
if (height > tiku_recycle_answer.getMeasuredHeight()) {
height = tiku_recycle_answer.getMeasuredHeight();
}
//保存测量宽度和测量高度
setMeasuredDimension(width, height);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (int i = 0; i < firstLetters.size(); i++) {
paint.setColor(i == choosedPosition ? Color.WHITE : context.getResources().getColor(R.color.color_368FFF));
float x = (getWidth() - paint.measureText(firstLetters.get(i))) / 2;
float y = (float) getHeight() / firstLetters.size();//每个字母的高度
if (i == choosedPosition) {
canvas.drawCircle((float) (getWidth() / 2), i * y + y / 2, bgRadius, backgroundPaint);
}
//垂直位置需要增加一个偏移量,上移两个像素,因为根据计算得到的是baseline,将字母上移,使其居中在圆内
canvas.drawText(firstLetters.get(i), x, (perTextHeight + y) / 2 + y * i-2, paint);
}
}
//触碰事件
//按下,松开,拖动
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
this.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
float y = event.getY();
//获取触摸到字母的位置
choosedPosition = (int) y * firstLetters.size() / getHeight();
//上滑超过边界,显示第一个
if (choosedPosition < 0) {
choosedPosition = 0;
}
//下滑超过边界,显示最后一个
if (choosedPosition >= firstLetters.size()) {
choosedPosition = firstLetters.size() - 1;
}
if (listener != null) {
//滑动A-Z字母联动外层数据
listener.onTouch(firstLetters.get(choosedPosition));
}
break;
case MotionEvent.ACTION_UP:
this.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
choosedPosition = -1;
if (listener != null) {
//滑动A-Z字母联动外层数据
listener.onRelease();
}
break;
}
//重绘
invalidate();
return true;
}
public void setFirstListener(OnTouchFirstListener listener) {
this.listener = listener;
}
/**
* OnTouchFirstListener 接口
* onTouch:触摸到了那个字母
* onRelease:up释放时中间显示的字母需要设置为GONE
*/
public interface OnTouchFirstListener {
void onTouch(String firstLetter);
void onRelease();
}
}
<declare-styleable name="SlideBar">
<attr name="letter_size" format="dimension" />
<attr name="letter_height" format="dimension" />
<attr name="letter_gap" format="dimension" />
<attr name="letter_bg_radius" format="dimension" />
</declare-styleable>
xml中引入,我的是constraintlayout,具体设置看自己的布局
<com.answer.view.SlideBar
android:id="@+id/slideBar"
android:layout_width="@dimen/dp_20"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/tiku_recycle_answer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guide_answer"
app:layout_constraintTop_toTopOf="@+id/tiku_recycle_answer"
app:letter_bg_radius="@dimen/dp_8"
app:letter_gap="@dimen/dp_6"
app:letter_height="@dimen/dp_10"
app:letter_size="@dimen/sp_10" />
private void handleSlideBarEvent() {
List<QuesCommentSubjectiveStuBean> datas = .getDatas();//获取处理后的数据,赋值给导航栏
ArrayList<String> letters = new ArrayList<>();
for (QuesCommentSubjectiveStuBean stuBean : datas) {
if (letters.contains(stuBean.getFirstLetter())) {
continue;
}
letters.add(stuBean.getFirstLetter());
}
slideBar.setFirstLetters(letters);
slideBar.setTiku_recycle_answer(tiku_recycle_answer);
slideBar.setFirstListener(new SlideBar.OnTouchFirstListener() {
@Override
public void onTouch(String firstLetter, float dy) {
tv_first_letter.setVisibility(VISIBLE);
tv_first_letter.setText(firstLetter);
ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) tv_first_letter.getLayoutParams();
//如果是第一个字母,修改提示框显示位置
layoutParams.topMargin = (int) dy + slideBar.getTop() - tv_first_letter.getMeasuredHeight() / 2;
//异常情况,点击最后一个字符,提示框显示不全的场景,如果显示位置超过屏幕,则靠底部显示
if ((int) dy + slideBar.getTop() + tv_first_letter.getMeasuredHeight() / 2 > tiku_recycle_answer.getBottom()) {
layoutParams.topMargin = tiku_recycle_answer.getBottom() - tv_first_letter.getMeasuredHeight();
}
tv_first_letter.setLayoutParams(layoutParams);
//滑动后移动到对应的位置,找到第一个匹配到首字母的学生,位移到此处
int newPosition = -1;
for (QuesCommentSubjectiveStuBean stuBean : datas) {
if (firstLetter.equals(stuBean.getFirstLetter())) {
newPosition = datas.indexOf(stuBean);
break;
}
}
//move时会多次触发,此处只响应第一次
if (newPosition != lastPosition) {
lastPosition = newPosition;
Lg.d(TAG, "questionComment-->--滑动导航栏跳转到首字母:" + firstLetter);
subJectLinearLayoutManager.scrollToPositionWithOffset(lastPosition, 0);
}
}
@Override
public void onRelease() {
postDelayed(new Runnable() {
@Override
public void run() {
lastPosition = -1;
tv_first_letter.setVisibility(GONE);
}
}, 200);
}
});
}
5.一个小问题。
用于放大显示选中字母的TextView在布局中,请设置为invisible,这样在加载xml布局时,会对这个控件进行测量和布局,只是不显示,这样我们才能获得tv_first_letter.getMeasuredHeight(),如果设置为gone,不会进行测量,获取的高度就为0,这样在第一次显示的时候就会有一个显示位置跳动的异常。设置为invisible就可以解决这个问题,目的就是让系统测量一下TextView的宽高,不想这么搞的话,在第4步之前手动测量一次也是可以的。
<TextView
android:id="@+id/tv_first_letter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/dp_2"
android:background="@mipmap/ic_bubble"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="C"
android:textColor="@color/color_ffffff"
android:textSize="@dimen/sp_18"
android:visibility="invisible"
app:layout_constraintEnd_toStartOf="@+id/guide_answer"
app:layout_constraintTop_toTopOf="parent" />
㈥ 请高手指点如何安装星际译王词库,放在android手机里用的
经过一个多月的开发终于完成了第一个可用版本。开发词典本身没花太多时间,网上收集词库转换格式比较花时间。目前主要功能有: 1.支持自定义多个词库。 2.输入单词变化时快速查询所有词库。 3.第一个字母索引列表。 4.简单的切换界面语言和字体设定功能。 5.无限后退、前进。 6.保留以前查询纪录。以后打算增加的功能: 1.TTS发音。 2.屏幕取词。 3.词库增加HTML格式支持,目前只支持TEXT。发几张图庆祝一下,呵呵。
㈦ android indexofkey什么用
indexOf()的用法:返回字符中indexof(string)中字串string在父串中首次出现的位置,从0开始!没有返回-1;方便判断和截取字符串! indexOf()定义和用法 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。 语法 stringObject。.
以 javascript来说, JS 中 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。 该方法将从头到尾地检索字符串 stringObject,看它是否含有子串 searchvalue。开始检索的位置在字符串的 fromindex 处或。
indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。即indexOf()括号内所包含的字符在该字符串内的循序位置,在第几位就返回几-1,类如:str1=asdfkju,str1.indexOf('d'),则返回的值是2。如果有重复的字符出现,以第一个字符为。
int indexOf(int ch,int fromIndex)函数:就是字符ch在字串fromindex位后出现的第一个位置.没有找到返加-1 eg:String str="a2dfcfar1bzvb"; System.out.println(str.indexOf(97,2)); 看这个例子,输出:6 a的ASCII为97,就从d开始找a找到了输出。
java.util.ArrayList.indexOf(Object) 方法返回指定元素的第一个匹配项的索引在此列表中,或者-1,如果此列表中不包含该元素。 声明 以下是java.util.ArrayList.indexOf()方法的声明 public int indexOf(Object o) 参数 o -- 要搜索的元素。 返。
几个经常用到的字符串的截取 string str="123abc456"; int i=3; 1 取字符串的前i个字符 str=str.Substring(0,i); // or str=str.Remove(i,str.Length-i); 2 去掉字符串的前i个字符: str=str.Remove(0,i); // or str=str.Substring(i); 3 从右边。
JAVA中String 类有一个方法为substring(int beginIndex, int endIndex),它返回一个新字符串,它是此字符串从指定的 beginIndex处开始,一直到索引 endIndex - 1处的字符组成的新字符串。因此,该子字符串的长度为 endIndex-beginIndex 。 String。
区别是: indexof指的是报告指定字符在此实例中的第一个匹配项的索引。搜索从指定字符位置开始,并检查指定数量的字符位置。 String.IndexOf 方法 (value, [startIndex], [count]) 要查找的 Unicode 字符。 对 value 的搜索区分大小写。 startIn。
㈧ android的全称前四个字母是什么
android本身就是个单词,所以它的前四个字母就是andr
㈨ 怎么给listview添加 快速索引条
实现步骤:
1.自定义一个名叫SlideBar 的View。
2.在布局文件中加入这个自定义的View。
3. 在Activity中处理监听事件。
接下来讲讲我是怎样实现的:
先来看SlideBar这个类:
packagecom.folyd.tuan.view;
importandroid.content.Context;
importandroid.graphics.Canvas;
importandroid.graphics.Color;
importandroid.graphics.Paint;
importandroid.graphics.Typeface;
importandroid.util.AttributeSet;
importandroid.view.MotionEvent;
importandroid.view.View;
/**
*自定义的View,实现ListViewA~Z快速索引效果
*
*@authorFolyd
*
*/
{
privatePaintpaint=newPaint();
;
//是否画出背景
privatebooleanshowBg=false;
//选中的项
privateintchoose=-1;
//准备好的A~Z的字母数组
publicstaticString[]letters={"#","A","B","C","D","E","F","G",
"H","I","J","K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z"};
//构造方法
publicSlideBar(Contextcontext){
super(context);
}
publicSlideBar(Contextcontext,AttributeSetattrs){
super(context,attrs);
}
@Override
protectedvoidonDraw(Canvascanvas){
super.onDraw(canvas);
//获取宽和高
intwidth=getWidth();
intheight=getHeight()-30;
//每个字母的高度
intsingleHeight=height/letters.length;
if(showBg){
//画出背景
canvas.drawColor(Color.parseColor("#55000000"));
}
//画字母
for(inti=0;i<letters.length;i++){
paint.setColor(Color.BLACK);
//设置字体格式
paint.setTypeface(Typeface.DEFAULT_BOLD);
paint.setAntiAlias(true);
paint.setTextSize(20f);
//如果这一项被选中,则换一种颜色画
if(i==choose){
paint.setColor(Color.parseColor("#F88701"));
paint.setFakeBoldText(true);
}
//要画的字母的x,y坐标
floatposX=width/2-paint.measureText(letters[i])/2;
floatposY=i*singleHeight+singleHeight;
//画出字母
canvas.drawText(letters[i],posX,posY,paint);
//重新设置画笔
paint.reset();
}
}
/**
*处理SlideBar的状态
*/
@Override
(MotionEventevent){
finalfloaty=event.getY();
//算出点击的字母的索引
finalintindex=(int)(y/getHeight()*letters.length);
//保存上次点击的字母的索引到oldChoose
finalintoldChoose=choose;
switch(event.getAction()){
caseMotionEvent.ACTION_DOWN:
showBg=true;
if(oldChoose!=index&&listenner!=null&&index>0
&&index<letters.length){
choose=index;
listenner.onTouchLetterChange(event,letters[index]);
invalidate();
}
break;
caseMotionEvent.ACTION_MOVE:
if(oldChoose!=index&&listenner!=null&&index>0
&&index<letters.length){
choose=index;
listenner.onTouchLetterChange(event,letters[index]);
invalidate();
}
break;
caseMotionEvent.ACTION_UP:
default:
showBg=false;
choose=-1;
if(listenner!=null&&index>0&&index<letters.length)
listenner.onTouchLetterChange(event,letters[index]);
invalidate();
break;
}
returntrue;
}
/**
*回调方法,注册监听器
*
*@paramlistenner
*/
(
){
this.listenner=listenner;
}
/**
*SlideBar的监听器接口
*
*@authorFolyd
*
*/
{
voidonTouchLetterChange(MotionEventevent,Strings);
}
}
然后在布局文件中加入这个自定义的控件:
<!--上面的代码省略掉了-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/line3"/>
<TextView
android:id="@+id/float_letter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:background="#F88701"
android:gravity="center"
android:textSize="40sp"
android:visibility="gone"/>
<com.folyd.tuan.view.SlideBar
android:id="@+id/slideBar"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"/>
</FrameLayout>然后在Activity中注册监听事件:
mSlideBar
.((){
@Override
publicvoidonTouchLetterChange(MotionEventevent,Strings){
float_letter.setText(s);
switch(event.getAction()){
caseMotionEvent.ACTION_DOWN:
caseMotionEvent.ACTION_MOVE:
float_letter.setVisibility(View.VISIBLE);
break;
caseMotionEvent.ACTION_UP:
default:
float_letter.postDelayed(newRunnable(){
@Override
publicvoidrun(){
float_letter.setVisibility(View.GONE);
}
},100);
break;
}
intposition=array.indexOf(s);//这个array就是传给自定义Adapter的
mListView.setSelection(position);//调用ListView的setSelection()方法就可实现了
}
});
㈩ android 如何输入首字母进行地址城市模糊检索
Android中ListView的A-Z字母排序和过滤搜索功能并且实现汉字转成拼音的功能,一般对联系人,城市列表等实现A-Z的排序,因为联系人和城市列表可以直接从数据库中获取它的汉字拼音,而对于一般的数据,实现A-Z的排序,基实只需要将汉字转换成拼音就行了。
以下为步骤:
SortModel 一个实体类,里面一个是ListView的name,另一个就是显示的name拼音的首字母。
2.SideBar类就是ListView右侧的字母索引View,需要使用setTextView(TextView mTextDialog)来设置用来显示当前按下的字母的TextView,以及使用方法来设置回调接口,在回调方法onTouchingLetterChanged(String s)中来处理不同的操作。
3.CharacterParser这个类是将汉字转换成拼音的类,该拼音没有声调的,该类是单例类,其中定义了三个方法,在这个demo中用到的是getSelling(String chs)方法,将词组转换成拼音。
4.ClearEditText类是自定义的一个在右侧有删除图片的EditText,当然也可以用Android原生的EditText,这里就不贴上代码了Android 带清除功能的输入框控件ClearEditText,仿IOS的输入框。
5.SortAdapter 数据的适配器类,该类需要实现SectionIndexer接口,该接口是用来控制ListView分组的。
6.最后运行效果