Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:clickable="true"
- android:focusable="true"
- android:background="#ffffff">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="textPersonName"
- android:ems="10"
- android:id="@+id/editableText"
- android:layout_gravity="center_horizontal"
- android:editable="true"
- android:hint="Search Here"
- android:padding="20dp"
- android:layout_marginTop="10dp"
- android:layout_marginBottom="10dp" />
- <ListView
- android:id="@+id/listSearch"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:footerDividersEnabled="false"
- android:headerDividersEnabled="false"
- android:paddingStart="15dp"
- android:paddingEnd="15dp" />
- </LinearLayout>
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedBundle) {
- View firstAccessView;
- if(savedBundle==null) {
- firstAccessView = inflater.inflate(R.layout.search_fragment_layout, null);
- ((ActionBarActivity)getActivity()).getSupportActionBar().setTitle("Search Friend");
- for(int i=0; i<8; i++){
- Contact c = new Contact(idContact[i], nameSurname[i], facebookId[i], timeStamp[i]);
- this.rows.add(c);
- }
- adapter = new SearchListAdapter(getActivity(), this.rows);
- list = (ListView) firstAccessView.findViewById(R.id.listSearch);
- list.setAdapter(adapter);
- list.setOnScrollListener(this);
- list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- //TODO Auto-generated method stub
- Toast.makeText(getActivity().getApplicationContext(), "item selected", Toast.LENGTH_SHORT).show();
- }
- });
- this.editableText = (TextView) firstAccessView.findViewById(R.id.editableText);
- this.editableText.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- List<Contact> temp = new ArrayList<Contact>();
- int length = editableText.getText().length();
- temp.clear();
- for(int i = 0; i<rows.size(); i++){
- if(editableText.getText().toString().equalsIgnoreCase("")){
- list.setAdapter(new SearchListAdapter(getActivity(), rows));
- }
- if(length < rows.get(i).getName().length()){
- if(editableText.getText().toString().equalsIgnoreCase((String)rows.get(i).getName().subSequence(0,length))){
- temp.add(rows.get(i));
- }
- }
- }
- if(temp.size()>0){
- list.setAdapter(new SearchListAdapter(getActivity(), temp));
- }
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- }else{
- firstAccessView = getView();
- }
- return firstAccessView;
- }
- list.setOnItemClickListener( new OnItemClickListener() {
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
- //code here
- });
Add Comment
Please, Sign In to add comment