Android的ListView的快速滚动和按字母顺序排列部分指标 [英] Android ListView with fast scroll and alphabetical section index
问题描述
如何触摸如图图像右侧字母面板上的字母时,增加testview? 请你帮助我好吗?下面是我的code。
在细节,我正在寻找一个完全像下面的图像的例子。目前,我没有数据的排序。当我点击右侧的字母面板上显示数据正常。但问题是触摸字母右边的字母板,我需要证明什么信他是pressing在图像(E)显示大尺寸的时候。我该怎么办呢,你能帮帮我吗?预先感谢您!
// MainActivity.java
公共类MainActivity扩展活动器具
SearchView.OnQueryTextListener,
SearchView.OnCloseListener {
私人IndexableListView的ListView;
私人搜索查看搜索;
EfficientAdapter objectAdapter;
EfficientAdapter2 objectAdapter1;
INT长度限制:Textlength = 0;
私人复选框checkStat,checkRoutine,checkTat;
私人的ArrayList<患者GT; patientListArray;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.homempleb);
Log.i(扫描,txtScanResult);
ActionItem nextItem =新ActionItem();
最后QuickAction quickAction =新QuickAction(这一点,QuickAction.VERTICAL);
quickAction.addActionItem(nextItem);
quickAction.setOnDismissListener(新QuickAction.OnDismissListener(){
@覆盖
公共无效onDismiss(){
Toast.makeText(getApplicationContext(),驳回,Toast.LENGTH_SHORT).show();
}
});
ListView控件=(IndexableListView)findViewById(R.id.homelistView);
listView.setTextFilterEnabled(真正的);
listView.setFastScrollEnabled(真正的);
listView.setFastScrollAlwaysVisible(真正的);
objectAdapter =新EfficientAdapter(本);
listView.setAdapter(objectAdapter);
}
@覆盖
公共布尔的OnClose(){
返回false;
}
@覆盖
公共布尔onQueryTextChange(字符串newText){
返回false;
}
@覆盖
公共布尔onQueryTextSubmit(查询字符串){
返回false;
}
}
...
// EfficientAdapter.java
公共类EfficientAdapter扩展了BaseAdapter实现SectionIndexer {
私人字符串mSections =#ABCDEFGHIJKLMNOPQRSTUVWXYZ;
ArrayList的<患者GT; patientListArray;
私人LayoutInflater mInflater;
私人上下文的背景下;
公共EfficientAdapter(上下文的背景下){
mInflater = LayoutInflater.from(上下文);
this.context =背景;
字符串patientListJson = CountriesList.jsonData;
的JSONObject jssson;
尝试 {
jssson =新的JSONObject(patientListJson);
patientListJson = jssson.getString(PostPatientDetailResult);
}赶上(JSONException E){
e.printStackTrace();
}
GSON GSON =新GSON();
JsonParser分析器=新JsonParser();
JsonArray Jarray = parser.parse(patientListJson).getAsJsonArray();
patientListArray =新的ArrayList<患者GT;();
对于(JsonElement OBJ:Jarray){
患者patientList = gson.fromJson(OBJ,Patient.class);
patientListArray.add(patientList);
Collections.sort(patientListArray,新的比较<对象>(){
@覆盖
公众诠释比较(对象01,对象02){
病人P1 =(患者)01;
患者P2 =(患者)O2;
返回p1.getName()与compareToIgnoreCase(p2.getName())。
}
});
}
}
公众诠释getCount将(){
返回patientListArray.size();
}
公共对象的getItem(INT位置){
返回的位置;
}
众长getItemId(INT位置){
返回的位置;
}
公共查看getView(INT位置,查看convertView,ViewGroup中父){
ViewHolder持有人;
如果(convertView == NULL){
convertView = mInflater.inflate(R.layout.homemplebrowview,NULL);
持有人=新ViewHolder();
holder.text1 =(TextView中)convertView.findViewById(R.id.name);
holder.text2 =(TextView中)convertView.findViewById(R.id.mrn);
holder.text3 =(TextView中)convertView.findViewById(R.id.date);
holder.text4 =(TextView中)convertView.findViewById(R.id.age);
holder.text5 =(TextView中)convertView.findViewById(R.id.gender);
holder.text6 =(TextView中)convertView.findViewById(R.id.wardno);
holder.text7 =(TextView中)convertView.findViewById(R.id.roomno);
holder.text8 =(TextView中)convertView.findViewById(R.id.bedno);
holder.btnList =(按钮)convertView.findViewById(R.id.listbutton);
holder.btnList.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
//意图下一=新的意图(背景下,SeviceDetails.class);
// context.startActivity(下);
}
});
convertView.setTag(保持器);
} 其他 {
支架=(ViewHolder)convertView.getTag();
}
holder.text1.setText(Util.formatN2H(patientListArray.get(位置).getName()));
holder.text2.setText(patientListArray.get(位置).getMrnNumber());
holder.text3.setText(Util.formatN2H(patientListArray.get(位置).getRoom()));
holder.text4.setText(Util.formatN2H(patientListArray.get(位置).getAge()));
holder.text5.setText(Util.formatN2H(patientListArray.get(位置).getGender()));
holder.text6.setText(Util.formatN2H(patientListArray.get(位置).getWard()));
holder.text7.setText(Util.formatN2H(patientListArray.get(位置).getRoom()));
holder.text8.setText(Util.formatN2H(patientListArray.get(位置).getBed()));
返回convertView;
}
静态类ViewHolder {
公众按钮btnList;
公众的TextView text8;
公众的TextView text7;
公众的TextView text6;
公众的TextView text5;
公共TextView的文本4;
公众的TextView文本1;
公众的TextView文本2;
公众的TextView文本3;
}
@覆盖
公共无效notifyDataSetChanged(){
super.notifyDataSetChanged();
}
// @覆盖
公众诠释getPositionForSection(INT部分){
//如果没有为当前部分没有项目,previous部分将被选中
的for(int i =节; I> = 0;我 - ){
对于(INT J = 0; J< getCount将(); J ++){
如果(我== 0){
//对于数字部分
对于(INT K = 0; K< = 9; k ++){
如果(StringMatcher.match(将String.valueOf(patientListArray.get(j)条.getName()。的charAt(0)),将String.valueOf(k))的)
复位J;
}
} 其他 {
如果(StringMatcher.match(将String.valueOf(patientListArray.get(j)条.getName()。的charAt(0)),
将String.valueOf(mSections.charAt(I))))
复位J;
}
}
}
返回0;
}
// @覆盖
公众诠释getSectionForPosition(INT位置){
返回0;
}
// @覆盖
公共对象[] getSections(){
的String []部分=新的String [mSections.length()];
的for(int i = 0; I< mSections.length();我++)
区段[I] =将String.valueOf(mSections.charAt(ⅰ));
返回段;
}
}
听到的是你所需要的 HTTPS一个凉爽的例子://github.com/woozzu/IndexableListView
为了编译项目,并摆脱韩国文字更新 StringMatcher
类
包com.woozzu.android.util;
公共类StringMatcher {
公共静态布尔匹配(字符串值,字符串关键字){
如果(价值== NULL ||关键字== NULL)
返回false;
如果(keyword.length()> value.length())
返回false;
INT I = 0,J = 0;
做 {
INT六= value.charAt(ⅰ);
INT KJ = keyword.charAt(J);
如果(isKorean(ⅵ)&安培;&安培; isInitialSound(KJ)){
} 其他 {
如果(六== KJ){
我++;
J ++;
}否则如果(J&0)
打破;
其他
我++;
}
}而(ⅰ&其中; value.length()&安培;&安培; J&其中; keyword.length());
返程(j == keyword.length())?真假;
}
私有静态布尔isKorean(int i)以{
返回false;
}
私有静态布尔isInitialSound(int i)以{
返回false;
}
}
How to add testview when touching a letter on right alphabet panel as shown in images? Could you please help me? Below is my code.
In details, I am looking for an example exactly like below image. Currently I did the sorting of data. When I click on right alphabet panel it shows the data properly. But the problem is when touching a letter the right alphabet panel I need to show what letter he is pressing in large size shown in image(E). How can I do it, could you please help me? Thank you in advance!
// MainActivity.java
public class MainActivity extends Activity implements
SearchView.OnQueryTextListener,
SearchView.OnCloseListener {
private IndexableListView listView;
private SearchView search;
EfficientAdapter objectAdapter;
EfficientAdapter2 objectAdapter1;
int textlength = 0;
private CheckBox checkStat, checkRoutine, checkTat;
private ArrayList<Patient> patientListArray;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homempleb);
Log.i("scan"," txtScanResult ");
ActionItem nextItem = new ActionItem();
final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);
quickAction.addActionItem(nextItem);
quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {
@Override
public void onDismiss() {
Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
}
});
listView = (IndexableListView) findViewById(R.id.homelistView);
listView.setTextFilterEnabled(true);
listView.setFastScrollEnabled(true);
listView.setFastScrollAlwaysVisible(true);
objectAdapter = new EfficientAdapter(this);
listView.setAdapter(objectAdapter);
}
@Override
public boolean onClose() {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
}
...
// EfficientAdapter.java
public class EfficientAdapter extends BaseAdapter implements SectionIndexer {
private String mSections = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ArrayList<Patient> patientListArray;
private LayoutInflater mInflater;
private Context context;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.context=context;
String patientListJson = CountriesList.jsonData;
JSONObject jssson;
try {
jssson = new JSONObject(patientListJson);
patientListJson = jssson.getString("PostPatientDetailResult");
} catch (JSONException e) {
e.printStackTrace();
}
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray Jarray = parser.parse(patientListJson).getAsJsonArray();
patientListArray = new ArrayList<Patient>();
for (JsonElement obj : Jarray) {
Patient patientList = gson.fromJson(obj, Patient.class);
patientListArray.add(patientList);
Collections.sort(patientListArray, new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
Patient p1 = (Patient) o1;
Patient p2 = (Patient) o2;
return p1.getName().compareToIgnoreCase(p2.getName());
}
});
}
}
public int getCount() {
return patientListArray.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.homemplebrowview, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.name);
holder.text2 = (TextView) convertView.findViewById(R.id.mrn);
holder.text3 = (TextView) convertView.findViewById(R.id.date);
holder.text4 = (TextView) convertView.findViewById(R.id.age);
holder.text5 = (TextView) convertView.findViewById(R.id.gender);
holder.text6 = (TextView) convertView.findViewById(R.id.wardno);
holder.text7 = (TextView) convertView.findViewById(R.id.roomno);
holder.text8 = (TextView) convertView.findViewById(R.id.bedno);
holder.btnList = (Button) convertView.findViewById(R.id.listbutton);
holder.btnList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Intent next=new Intent(context, SeviceDetails.class);
// context.startActivity(next);
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text1.setText(Util.formatN2H(patientListArray.get(position).getName()));
holder.text2.setText(patientListArray.get(position).getMrnNumber());
holder.text3.setText(Util.formatN2H(patientListArray.get(position).getRoom()));
holder.text4.setText(Util.formatN2H(patientListArray.get(position).getAge()));
holder.text5.setText(Util.formatN2H( patientListArray.get(position).getGender()));
holder.text6.setText(Util.formatN2H(patientListArray.get(position).getWard()));
holder.text7.setText(Util.formatN2H(patientListArray.get(position).getRoom()));
holder.text8.setText(Util.formatN2H(patientListArray.get(position).getBed()));
return convertView;
}
static class ViewHolder {
public Button btnList;
public TextView text8;
public TextView text7;
public TextView text6;
public TextView text5;
public TextView text4;
public TextView text1;
public TextView text2;
public TextView text3;
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
//@Override
public int getPositionForSection(int section) {
// If there is no item for current section, previous section will be selected
for (int i = section; i >= 0; i--) {
for (int j = 0; j < getCount(); j++) {
if (i == 0) {
// For numeric section
for (int k = 0; k <= 9; k++) {
if (StringMatcher.match(String.valueOf(patientListArray.get(j).getName().charAt(0)), String.valueOf(k)))
return j;
}
} else {
if (StringMatcher.match(String.valueOf(patientListArray.get(j).getName().charAt(0)),
String.valueOf(mSections.charAt(i))))
return j;
}
}
}
return 0;
}
//@Override
public int getSectionForPosition(int position) {
return 0;
}
//@Override
public Object[] getSections() {
String[] sections = new String[mSections.length()];
for (int i = 0; i < mSections.length(); i++)
sections[i] = String.valueOf(mSections.charAt(i));
return sections;
}
}
Hear is one cool example of what you need https://github.com/woozzu/IndexableListView
IN order to compile the project and get rid of korean text update the StringMatcher
class
package com.woozzu.android.util;
public class StringMatcher {
public static boolean match(String value, String keyword) {
if (value == null || keyword == null)
return false;
if (keyword.length() > value.length())
return false;
int i = 0, j = 0;
do {
int vi = value.charAt(i);
int kj = keyword.charAt(j);
if (isKorean(vi) && isInitialSound(kj)) {
} else {
if (vi == kj) {
i++;
j++;
} else if (j > 0)
break;
else
i++;
}
} while (i < value.length() && j < keyword.length());
return (j == keyword.length())? true : false;
}
private static boolean isKorean(int i) {
return false;
}
private static boolean isInitialSound(int i) {
return false;
}
}
这篇关于Android的ListView的快速滚动和按字母顺序排列部分指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!