Android ListView,具有快速滚动和按字母顺序的部分索引

Android ListView,具有快速滚动和按字母顺序的部分索引,android,android-layout,android-intent,android-emulator,android-widget,Android,Android Layout,Android Intent,Android Emulator,Android Widget,如图所示,当触摸右侧字母面板上的字母时,如何添加testview? 你能帮帮我吗?下面是我的代码 具体来说,我正在寻找一个与下图完全相同的示例。目前我对数据进行了排序。当我点击右字母面板时,它正确地显示了数据。但问题是,当触摸右侧字母面板上的字母时,我需要显示他按下的字母的大尺寸,如图(E)所示。我怎么做,你能帮我吗?提前谢谢你 //MainActivity.java 公共类MainActivity扩展活动实现 SearchView.OnQueryTextListener, SearchVie

如图所示,当触摸右侧字母面板上的字母时,如何添加testview? 你能帮帮我吗?下面是我的代码

具体来说,我正在寻找一个与下图完全相同的示例。目前我对数据进行了排序。当我点击右字母面板时,它正确地显示了数据。但问题是,当触摸右侧字母面板上的字母时,我需要显示他按下的字母的大尺寸,如图(E)所示。我怎么做,你能帮我吗?提前谢谢你

//MainActivity.java
公共类MainActivity扩展活动实现
SearchView.OnQueryTextListener,
SearchView.OnCloseListener{
私有索引列表视图;
私有搜索视图搜索;
高效适配器;
高效适配器2对象适配器1;
int textlength=0;
私有复选框checkStat、checkRoutine、checkTat;
私人ArrayList PatientListaray;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.homempleb);
Log.i(“扫描”、“txtScanResult”);
ActionItem nextItem=新的ActionItem();
final QuickAction QuickAction=新的QuickAction(这是QuickAction.VERTICAL);
quickAction.addActionItem(nextItem);
quickAction.setOnDismissListener(新的quickAction.OnDismissListener(){
@凌驾
公共空间{
Toast.makeText(getApplicationContext(),“discomered”,Toast.LENGTH_SHORT.show();
}
});
listView=(IndexableListView)findViewById(R.id.homelistView);
setTextFilterEnabled(true);
setFastScrollEnabled(true);
setFastScrollAlwaysVisible(true);
objectAdapter=new EfficientAdapter(此);
setAdapter(objectAdapter);
}
@凌驾
公共布尔onClose(){
返回false;
}
@凌驾
公共布尔onQueryTextChange(字符串newText){
返回false;
}
@凌驾
公共布尔值onQueryTextSubmit(字符串查询){
返回false;
}
}

//EfficientAdapter.java
公共类EfficientAdapter扩展BaseAdapter实现SectionIndexer{
私有字符串mSections=“#abcdefghijklmnopqrstuvxyz”;
ArrayList耐心等待;
私人停车场;
私人语境;
公共效率适配器(上下文){
mInflater=LayoutInflater.from(上下文);
this.context=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();
for(JsonElement对象:Jarray){
Patient patientList=gson.fromJson(obj,Patient.class);
patientList.add(patientList);
Collections.sort(patientListArray,新的Comparator(){
@凌驾
公共整数比较(对象o1、对象o2){
患者p1=(患者)o1;
患者p2=(患者)o2;
返回p1.getName().compareToIgnoreCase(p2.getName());
}
});
}
}
public int getCount(){
返回patientListArray.size();
}
公共对象getItem(int位置){
返回位置;
}
公共长getItemId(int位置){
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
convertView=mInflater.inflate(R.layout.homemplebrowview,null);
holder=新的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(){
@凌驾
公共void onClick(视图v){
//Intent next=新的Intent(上下文,SeviceDetails.class);
//背景。开始触觉(下一步);
}
});
convertView.setTag(支架);
}否则{
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.format2h(patientListArray.get(position.getBed
// 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;
    }

}
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;
    }
}
//method to display the side indexed scroll list of alphabets 
    public void displayAlphabetsList() {
        final List<String> listOfAlphabet = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            char alphabet = (char) (ASCII_VALUE_OF_A + i);
            listOfAlphabet.add(String.valueOf(alphabet));
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, listOfAlphabet);
       alphabets_List_View.setAdapter(adapter);

        alphabets_List_View.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ///scroll the recycler view to that position where matching letter was found
                int positionToScroll = 0;
                for (int i = 0; i < mContacts.size(); i++) {
                    if (mContacts.get(i).getFirstName().startsWith(listOfAlphabet.get(position)))
                        break;
                    else
                        positionToScroll++;
                }
                recyclerView.scrollToPosition(positionToScroll);
            }
        });
    }