具有复选框和搜索功能的Expandablelistview如何处理搜索列表视图和扩展列表项中的多个选择

时间:2015-01-28 12:30:40

标签: android search expandablelistview

我的MainActivity是如何在expandablelistview中实现搜索功能,当搜索框为空时显示复选框,显示expandablelistview,输入搜索框的单词字母显示列表视图。

public class MainActivity extends Activity {

private ExpandableListAdapter expandableListAdapter;
private ExpandableListView expandableListView;
// private ArrayList<Category> categories;
List<String> expandableListTitle;
HashMap<String, List<String>> expandableListDetail;
protected Context mContext;
private ListView listView;
private EditText searchField;
private TextView cancelTextView;
CheckBox chkIos;
Button display;
private BaseSearchableListAdapter searchableListAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.activity_main);
    mContext = this;
    expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
    searchField = (EditText) findViewById(R.id.search_friends_field);
    cancelTextView = (TextView) findViewById(R.id.cancel_button);
    listView=(ListView)findViewById(R.id.list);
    listView.setVisibility(View.GONE);
    expandableListDetail = ExpandableListDataPump.getData();
    expandableListTitle = new ArrayList<String>(expandableListDetail.keySet());
    expandableListAdapter = new ExpandableListAdapter(this,expandableListTitle, expandableListDetail);
    expandableListView.setAdapter(expandableListAdapter);
    expandableListView.setChoiceMode(expandableListView.CHOICE_MODE_MULTIPLE);      
    display = (Button) findViewById(R.id.button1);
    searchField.addTextChangedListener(watch);
    cancelTextView.setOnClickListener(new OnClickListener() {


        public void onClick(View arg0) {
            cancelFilter(null);
        }
    });

    display.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // Create string buffer to

            StringBuffer OUTPUT = new StringBuffer();
            OUTPUT.append("These are selected/n").append(
                    expandableListAdapter.selected_profileid);

            Toast.makeText(MainActivity.this, OUTPUT.toString(),
                    Toast.LENGTH_LONG).show();

        }
    });

    // searchView = (EditText) findViewById(R.id.search);
    expandableListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent,
                View clickedView, int groupPosition, int childPosition,
                long id) {

            return true;

        }
    });

}

0 个答案:

没有答案