列表视图搜索在弹出对话框不工作 [英] Listview Search not working in Popup dialog

查看:310
本文介绍了列表视图搜索在弹出对话框不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在其中一个弹出警告对话框内显示的列表视图搜索功能。该列表显示了罚款和搜索的EDITTEXT也显示出来。但是,搜索功能无法正常工作的。

I am trying to implement a search functionality in a listview which is displayed inside a popup alert dialog. The list shows fine and the Edittext for the search is also showing up. But the search function is not working as at all.

我提到本教程实现相同的。我想实现的是,对话框会先打开,而另一个功能将下载数据并填充为列表中的适配器。一旦数据被下载的列表将在对话框内进行填充。搜索应该工作,一旦适配器填充和列表显示出来。

I had referred this tutorial to implement the same. What I want to achieve is that, the dialog will open first, while another function will download the data and populate the adapter for the list. Once the data is downloaded the list will be populated inside the dialog. The search should work once the adapter is populated and list shows up.

以显示弹出的功能:

private void showCollegePopUp(){
        QustomDialogBuilder builder = new QustomDialogBuilder(EditYourProfile.this);
        builder.setDividerColor(ColorController.bright_green);

        View v = builder.setCustomView(R.layout.dialog_friend_layout, this);

        final ListView list = (ListView) v.findViewById(R.id.dialog_list_view_friends);
        LayoutInflater inflater = (LayoutInflater)EditYourProfile.this.getSystemService
                (Context.LAYOUT_INFLATER_SERVICE);
        footerView = inflater.inflate(R.layout.add_college_list_footer, list, false);
        list.addFooterView(footerView);
        inputSearch = (EditText) findViewById(R.id.inputSearch);
        if (adapter != null) {
            inputSearch.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                    // When user changed the Text
                    EditYourProfile.this.adapter.getFilter().filter(cs);
                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                                              int arg3) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable arg0) {
                    // TODO Auto-generated method stub
                }
            });
        }
        TextView textView = (TextView) v.findViewById(R.id.add_college);

        textView.setTypeface(TypeFaceController.generalTextFace(EditYourProfile.this));

        LinearLayout footer_linear_layout = (LinearLayout)v.findViewById(R.id.footer_linear_layout);
        footer_linear_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(EditYourProfile.this, "hello", Toast.LENGTH_LONG).show();
            }
        });
        footerView.setVisibility(View.GONE);

        if (listOfCollegeCourseNames.size() == 0) {
            listOfCollegeCourseNames.add("Grabbing colleges...");
        }

        adapter = new CustomDialogAdapterBasic(EditYourProfile.this, android.R.id.text1, listOfCollegeCourseNames);
        list.setPadding(16, 0, 0, 0);
        list.setAdapter(adapter);

        builder.setTitle("Select your college");
        builder.setMessage("Choose College from the list:");
        builder.setCancelable(true);

        builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1){

            }
        });

        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                // Do as you please

                if (adapter.getItem(position).toString().equals(collegeData.get(position).getNameForCollege())
                        || adapter.getItem(position).toString().equals(collegeData.get(position).getStudentsNameForCollege())) {

                    newCollegeName = adapter.getItem(position).toString();

                    collegeEditPage.setText(Html.fromHtml((newCollegeName)));// +
                                                                                // edit));
                    //courseEditPage.setText(Html.fromHtml(("Must choose new course")));// +
                                                                                        // edit));
                    // course doesn't exist anymore.
                    studentObject.setCourseName(null);
                    studentObject.setCollegeName(newCollegeName);

                    if (EditYourProfile.this.alertDialog != null) {
                        EditYourProfile.this.alertDialog.dismiss();
                        // Refresh the list used.
                        listOfCollegeCourseNames = new ArrayList<String>();
                        newCollegeId = collegeData.get(position).getCollegeUnqId();
                        studentObject.setCollegeId(newCollegeId);
                    }

                }

            }
        });

        this.alertDialog = builder.create();
        this.alertDialog.setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog){
                AlertDialog alertDialog = (AlertDialog) dialog;
                Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                button.setTextSize(17);
                button.setTypeface(TypeFaceController.titleFace(getApplicationContext()));
            }
        });
        alertDialog.show();

    }

从数据库中接收数据的功能:

private void fetchAllCollegesAndDisplay(){
        final List<College> collegeDetailList = new ArrayList<College>();
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Colleges");
        query.addAscendingOrder("name");

        query.findInBackground(new FindCallback<ParseObject>() {

            @Override
            public void done(List<ParseObject> objects, com.parse.ParseException e){
                if (e == null) {
                    Log.e("Objects size", "" + objects.size());
                        for (int i = 0; i < objects.size(); i++) {
                            if (objects.get(i).get("status") != null) {
                                if (objects.get(i).getBoolean("status") == true){
                                    College college = new College();
                                    college.setNameForCollege(objects.get(i).get("name").toString());
                                    college.setCollegeUnqId(objects.get(i).getObjectId()); // Grab
                                    collegeDetailList.add(college);
                                }

                            }
                        }
                    generateList(collegeDetailList);

                }

            }

        });
    }

填充列表功能:

private void generateList(List<?> collegeOrCourseList){
        listOfCollegeCourseNames.remove(0);

        if (collegeOrCourseList.size() != 0) {

            // Check if the list is of type College.
            if (collegeOrCourseList.get(0) instanceof College) {
                for (Object c : collegeOrCourseList) {

                    if (((College) c).getStudentsNameForCollege() != null) {
                        //listOfCollegeCourseNames.add(((College) c).getStudentsNameForCollege());
                        listOfCollegeCourseNames.add(((College) c ).getNameForCollege());
                    } else

                    if (((College) c).getNameForCollege() != null) {
                        listOfCollegeCourseNames.add(((College) c).getNameForCollege());
                    }

                    collegeData.add((College) c);
                    adapter.notifyDataSetChanged();

                }
                footerView.setVisibility(View.VISIBLE);
            }

            if (collegeOrCourseList.get(0) instanceof Course) {
                courseData.clear();
                for (Object c : collegeOrCourseList) {
                    listOfCollegeCourseNames.add(((Course) c).getCourse());
                    courseData.add((Course) c);
                    adapter.notifyDataSetChanged();

                }
            }

        }
    }

适配器的code:

public class CustomDialogAdapterBasic extends ArrayAdapter<String> {

    Context context;
    List<String> valuesComingIn = new ArrayList<String>();



    public CustomDialogAdapterBasic(Context context, int resource, List<String> listComingIn) {
        super(context, resource);
        this.context = context;
        this.valuesComingIn = listComingIn;
    }


    public void updateBrowser() {
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return valuesComingIn.size();
    }

    public String getItem(int position) throws IndexOutOfBoundsException {
        return valuesComingIn.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean isEnabled(int position) {
        return true;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.qustom_layout_list, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.basic_text_view);

        textView.setTypeface(TypeFaceController.generalTextFace(context));
        textView.setText(getItem(position));

        return rowView;
    }
}

请让我知道我错了。为什么不正常的搜索?

Please let me know where I am going wrong. Why is the search not working?

推荐答案

从下面

inputSearch =(EditText上)findViewById(R.id.inputSearch);

inputSearch = (EditText) findViewById(R.id.inputSearch);

inputSearch =(EditText上)v.findViewById(R.id.inputSearch);

inputSearch = (EditText) v.findViewById(R.id.inputSearch);

这篇关于列表视图搜索在弹出对话框不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆