Search Dialog


Last Updated:

  1. awmayhall

    awmayhall New Member This Topic's Starter

    Joined:
    Oct 24, 2010
    Messages:
    4
    Likes Received:
    0
    Hey guys Im working on a custom dialog box so people can search for their friends in my application. So I have made a custom dialog box containing a list view from a ListActivity, Inside each row their is a image the users avatar and to the right the users name, click on the results the application will take you to their page and what not. What Im actually having problems with is creating a Edit text and a search button ontop of the dialog box so it would look something like this

    [​IMG]

    The Black is the activity running in the background the white is dialog box
    a editable text for searching and a search button to initiate the search the results are displayed below in a scroll view with an icon and the username, now i just need to keep the search box only at the top. hers some mock code what im working with

    Code (Text):
    1. package com.appsand.proto;
    2.  
    3. import android.app.Activity;
    4. import android.app.ListActivity;
    5. import android.content.Context;
    6. import android.content.Intent;
    7. import android.graphics.Bitmap;
    8. import android.os.Bundle;
    9. import android.view.LayoutInflater;
    10. import android.view.View;
    11. import android.view.ViewGroup;
    12. import android.view.Window;
    13. import android.widget.ArrayAdapter;
    14. import android.widget.ImageView;
    15. import android.widget.ListView;
    16. import android.widget.TextView;
    17.  
    18. public class AppSandSearchDialogActivity extends ListActivity
    19. {
    20.     private static final int TAKE_AVATAR_DEFAULT_GALLERY_REQUEST = 1;
    21.     private static final int TAKE_AVATAR_USER_GALLERY_REQUEST = 2;
    22.    
    23.     /** Called when the activity is first created. */
    24.     @Override
    25.     public void onCreate(Bundle savedInstanceState)
    26.     {
    27.         super.onCreate(savedInstanceState);
    28.         requestWindowFeature(Window.FEATURE_NO_TITLE);
    29.  
    30.         //setContentView(R.layout.general_settings);       
    31.  
    32.         final String[] items =
    33.         {
    34.                 "Hello",
    35.                 "World",
    36.         };
    37.  
    38.         class CustomImageAdapter extends ArrayAdapter<String>
    39.         {
    40.  
    41.             public CustomImageAdapter(Context context, int textViewResourceId, String[] objects)
    42.             {
    43.                 super(context, textViewResourceId, objects);
    44.                 // TODO Auto-generated constructor stub
    45.             }
    46.  
    47.             @Override
    48.             public View getView(int position, View convertView, ViewGroup parent)
    49.             {
    50.                 // TODO Auto-generated method stub
    51.                 // return super.getView(position, convertView, parent);
    52.                 View row = convertView;
    53.  
    54.                 if(row==null)
    55.                 {
    56.                     LayoutInflater inflater=getLayoutInflater();
    57.                     row=inflater.inflate(R.layout.search_items, parent, false);
    58.  
    59.                 }
    60.  
    61.                 TextView label=(TextView)row.findViewById(R.id.UsernameResults);
    62.                 label.setText(items[position]);
    63.                 ImageView icon=(ImageView)row.findViewById(R.id.UserIconResults);
    64.                 icon.setImageResource(R.drawable.icon);
    65.  
    66.                 return row;
    67.             }
    68.         }
    69.        
    70.         setListAdapter(new CustomImageAdapter(AppSandSearchDialogActivity.this, android.R.layout.simple_list_item_1, items));
    71.     }
    72.  
    73.     @Override
    74.     protected void onListItemClick(ListView l, View v, int position, long id)
    75.     {
    76.         // TODO Auto-generated method stub
    77.         //super.onListItemClick(l, v, position, id);
    78.                
    79.     }
    80. }
    heres some xml now this just handles the results only, ive trie creating a search.xml its below this one

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2.  
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="horizontal"
    5.     android:layout_width="wrap_content"
    6.     android:layout_height="wrap_content"
    7.     android:background="@android:color/white">
    8.  
    9.     <LinearLayout
    10.         android:orientation="horizontal"
    11.         android:paddingTop="10dp"
    12.         android:paddingLeft="10dp"
    13.         android:paddingRight="10dp"
    14.         android:layout_width="fill_parent"
    15.         android:layout_height="wrap_content"
    16.         android:background="@android:color/white">    
    17.        
    18.         <ScrollView
    19.             android:id="@+id/ScrollViewSearchView"
    20.             android:layout_width="fill_parent"
    21.             android:layout_height="fill_parent">
    22.            
    23.             <LinearLayout
    24.                 android:paddingTop="10dp"
    25.                 android:paddingLeft="10dp"
    26.                 android:paddingRight="10dp"
    27.                 android:layout_width="fill_parent"
    28.                 android:layout_height="wrap_content">
    29.    
    30.                 <ImageView
    31.                     android:id="@+id/UserIconResults"
    32.                     android:src="@drawable/icon"
    33.                     android:layout_width="50dp"
    34.                     android:layout_height="50dp"/>     
    35.    
    36.                 <TextView
    37.                     android:id="@+id/UsernameResults"
    38.                     android:paddingTop="15dp"
    39.                     android:paddingLeft="15dp"
    40.                     android:gravity="center_vertical"
    41.                     android:layout_gravity="center_horizontal"
    42.                     android:layout_width="fill_parent"
    43.                     android:layout_height="wrap_content"
    44.                     android:textSize="15px"
    45.                     android:text="text"
    46.                     android:textColor="@android:color/white"/> 
    47.             </LinearLayout>        
    48.         </ScrollView>      
    49.     </LinearLayout>
    50. </LinearLayout>
    51.  
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="horizontal"
    5.     android:layout_width="wrap_content"
    6.     android:layout_height="wrap_content"
    7.     android:background="@android:color/black">
    8.    
    9.     <EditText
    10.         android:text="@+id/EditText01"
    11.         android:id="@+id/EditTextSearchText"
    12.         android:layout_width="wrap_content"
    13.         android:layout_height="wrap_content">
    14.     </EditText>
    15.    
    16.     <ImageButton
    17.         android:id="@+id/ImageButtonSearchButton"
    18.         android:layout_width="wrap_content"
    19.         android:layout_height="wrap_content">
    20.     </ImageButton>
    21.    
    22.     <ListView
    23.             android:layout_height="wrap_content"
    24.             android:id="@+id/ListViewResults"
    25.             android:layout_width="fill_parent"
    26.             android:divider="?android:attr/listDivider"
    27.             android:dividerHeight="4px"
    28.             android:layout_alignParentTop="true">
    29.     </ListView>
    30. </LinearLayout>
    so this is all just mock stuff but is essentially what im working with,

    any ideas on how to do this would be appreciated.
     

    Advertisement
  2. awmayhall

    awmayhall New Member This Topic's Starter

    Joined:
    Oct 24, 2010
    Messages:
    4
    Likes Received:
    0
    well Im getting a little closer, It still need some work but ill post new code shortly
     
  3. awmayhall

    awmayhall New Member This Topic's Starter

    Joined:
    Oct 24, 2010
    Messages:
    4
    Likes Received:
    0
    okay so i changed a few things but my biggest thing is getting this xml straight the search box and button are appearing to the left of the results.... heres the new code and heres the xml files

    Code (Text):
    1. package com.appsand.proto;
    2.  
    3. import android.app.Activity;
    4. import android.content.Context;
    5. import android.content.Intent;
    6. import android.graphics.Bitmap;
    7. import android.os.Bundle;
    8. import android.view.LayoutInflater;
    9. import android.view.View;
    10. import android.view.ViewGroup;
    11. import android.view.Window;
    12. import android.widget.AdapterView;
    13. import android.widget.ArrayAdapter;
    14. import android.widget.ImageView;
    15. import android.widget.ListView;
    16. import android.widget.TextView;
    17.  
    18. public class AppSandSearchDialogActivity extends Activity
    19. {
    20.     private static final int TAKE_AVATAR_DEFAULT_GALLERY_REQUEST = 1;
    21.     private static final int TAKE_AVATAR_USER_GALLERY_REQUEST = 2;
    22.    
    23.     /** Called when the activity is first created. */
    24.     @Override
    25.     public void onCreate(Bundle savedInstanceState)
    26.     {
    27.         super.onCreate(savedInstanceState);
    28.         requestWindowFeature(Window.FEATURE_NO_TITLE);
    29.         setContentView(R.layout.search);       
    30.  
    31.         final String[] items =
    32.         {
    33.                 getResources().getString(R.string.default_avatar),
    34.                 getResources().getString(R.string.user_avatar),
    35.         };
    36.  
    37.         class CustomImageAdapter extends ArrayAdapter<String>
    38.         {
    39.  
    40.             public CustomImageAdapter(Context context, int textViewResourceId, String[] objects)
    41.             {
    42.                 super(context, textViewResourceId, objects);
    43.                 // TODO Auto-generated constructor stub
    44.             }
    45.  
    46.             @Override
    47.             public View getView(int position, View convertView, ViewGroup parent)
    48.             {
    49.                 // TODO Auto-generated method stub
    50.                 // return super.getView(position, convertView, parent);
    51.                 View row = convertView;
    52.  
    53.                 if(row==null)
    54.                 {
    55.                     LayoutInflater inflater=getLayoutInflater();
    56.                     row=inflater.inflate(R.layout.search_items, parent, false);
    57.                 }
    58.  
    59.                 TextView label=(TextView)row.findViewById(R.id.UsernameResults);
    60.                 label.setText(items[position]);
    61.                 ImageView icon=(ImageView)row.findViewById(R.id.UserIconResults);
    62.                 return row;
    63.             }
    64.         }
    65.         ListView resultsList = (ListView) findViewById(R.id.ListViewResults);
    66.         resultsList.setAdapter(new CustomImageAdapter(AppSandSearchDialogActivity.this, R.layout.search, items));
    67.    
    68.  
    69.     resultsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
    70.     {
    71.         public void onItemClick(AdapterView<?> parent,View itemClicked,int position,long id)
    72.         {
    73.         // TODO Auto-generated method stub
    74.         //super.onListItemClick(l, v, position, id);
    75.         }});
    76.     }
    77. }
    base xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="horizontal"
    5.     android:layout_width="wrap_content"
    6.     android:layout_height="wrap_content"
    7.     android:background="@android:color/black">
    8.    
    9.     <LinearLayout
    10.         android:orientation="horizontal"
    11.         android:layout_width="fill_parent"
    12.         android:layout_height="wrap_content"
    13.         android:background="@android:color/black">
    14.    
    15.         <EditText
    16.             android:text="@+id/EditText01"
    17.             android:id="@+id/EditTextSearchText"
    18.             android:layout_width="fill_parent"
    19.             android:layout_height="wrap_content">
    20.         </EditText>
    21.    
    22.         <ImageButton
    23.             android:id="@+id/ImageButtonSearchButton"
    24.             android:layout_width="wrap_content"
    25.             android:layout_height="wrap_content">
    26.         </ImageButton>
    27.     </LinearLayout>            
    28.    
    29.     <LinearLayout
    30.         android:background="@android:color/white"
    31.         android:layout_width="fill_parent"
    32.         android:layout_height="wrap_content">
    33.    
    34.         <ListView
    35.             android:layout_height="wrap_content"
    36.             android:id="@+id/ListViewResults"
    37.             android:layout_width="fill_parent"
    38.             android:divider="?android:attr/listDivider"
    39.             android:dividerHeight="4px"
    40.             android:layout_alignParentTop="true">
    41.         </ListView>
    42.     </LinearLayout>
    43. </LinearLayout>
    items xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="horizontal"
    5.     android:paddingTop="10dp"
    6.     android:paddingLeft="10dp"
    7.     android:paddingRight="10dp"
    8.     android:layout_width="fill_parent"
    9.     android:layout_height="wrap_content"
    10.     android:background="@android:color/white">    
    11.    
    12.     <ImageView
    13.         android:id="@+id/UserIconResults"
    14.         android:src="@drawable/icon"
    15.         android:layout_width="50dp"
    16.         android:layout_height="50dp"/>     
    17.    
    18.     <TextView
    19.         android:id="@+id/UsernameResults"
    20.         android:paddingTop="15dp"
    21.         android:paddingLeft="15dp"
    22.         android:gravity="center_vertical"
    23.         android:layout_gravity="center_horizontal"
    24.         android:layout_width="fill_parent"
    25.         android:layout_height="wrap_content"
    26.         android:textSize="15px"
    27.         android:text="text"
    28.         android:textColor="@android:color/black"/> 
    29. </LinearLayout>    
     

Share This Page

Loading...