Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Discussion > Android Lounge

Android Lounge A place for general Android discussion and questions.



Reply
 
LinkBack Thread Tools
Old October 30th, 2010, 02:22 PM   #1 (permalink)
New Member
 
Join Date: Oct 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Notsure Search Dialog

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



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:
package com.appsand.proto;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class AppSandSearchDialogActivity extends ListActivity 
{
	private static final int TAKE_AVATAR_DEFAULT_GALLERY_REQUEST = 1;
	private static final int TAKE_AVATAR_USER_GALLERY_REQUEST = 2;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		//setContentView(R.layout.general_settings);		

		final String[] items = 
		{
				"Hello",
				"World",
		};

		class CustomImageAdapter extends ArrayAdapter<String> 
		{

			public CustomImageAdapter(Context context, int textViewResourceId, String[] objects) 
			{
				super(context, textViewResourceId, objects);
				// TODO Auto-generated constructor stub
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) 
			{
				// TODO Auto-generated method stub
				// return super.getView(position, convertView, parent);
				View row = convertView;

				if(row==null)
				{
					LayoutInflater inflater=getLayoutInflater();
					row=inflater.inflate(R.layout.search_items, parent, false);

				}

				TextView label=(TextView)row.findViewById(R.id.UsernameResults);
				label.setText(items[position]);
				ImageView icon=(ImageView)row.findViewById(R.id.UserIconResults);
				icon.setImageResource(R.drawable.icon);

				return row;
			}
		}
		
		setListAdapter(new CustomImageAdapter(AppSandSearchDialogActivity.this, android.R.layout.simple_list_item_1, items));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) 
	{
		// TODO Auto-generated method stub
		//super.onListItemClick(l, v, position, id);
				
	}
}
heres some xml now this just handles the results only, ive trie creating a search.xml its below this one

Code:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/white"> 

	<LinearLayout
	    android:orientation="horizontal"
	    android:paddingTop="10dp"
	    android:paddingLeft="10dp"
	    android:paddingRight="10dp"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:background="@android:color/white">    
        
    	<ScrollView 
			android:id="@+id/ScrollViewSearchView" 
			android:layout_width="fill_parent" 
			android:layout_height="fill_parent"> 
			
			<LinearLayout
	    		android:paddingTop="10dp"
	    		android:paddingLeft="10dp"
	    		android:paddingRight="10dp"
	   		    android:layout_width="fill_parent"
	    		android:layout_height="wrap_content">
    
				<ImageView 
					android:id="@+id/UserIconResults"
					android:src="@drawable/icon"
					android:layout_width="50dp"
					android:layout_height="50dp"/>	    
    
				<TextView 
					android:id="@+id/UsernameResults"
					android:paddingTop="15dp"
					android:paddingLeft="15dp"
					android:gravity="center_vertical"
					android:layout_gravity="center_horizontal"
					android:layout_width="fill_parent"
					android:layout_height="wrap_content"
					android:textSize="15px" 
					android:text="text"
					android:textColor="@android:color/white"/>	
			</LinearLayout>			
		</ScrollView>		
	</LinearLayout> 
</LinearLayout>
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/black">
	
	<EditText 
		android:text="@+id/EditText01" 
		android:id="@+id/EditTextSearchText" 
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content">
	</EditText>
	
	<ImageButton 
		android:id="@+id/ImageButtonSearchButton" 
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content">
	</ImageButton>
	
	<ListView
            android:layout_height="wrap_content"
            android:id="@+id/ListViewResults"
            android:layout_width="fill_parent"
            android:divider="?android:attr/listDivider"
            android:dividerHeight="4px"
            android:layout_alignParentTop="true">
    </ListView>
</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.

awmayhall is offline  
Reply With Quote
Sponsors
Old October 30th, 2010, 02:45 PM   #2 (permalink)
New Member
 
Join Date: Oct 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well Im getting a little closer, It still need some work but ill post new code shortly
awmayhall is offline  
Reply With Quote
Old October 30th, 2010, 03:23 PM   #3 (permalink)
New Member
 
Join Date: Oct 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Notsure Xml help

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:
package com.appsand.proto;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class AppSandSearchDialogActivity extends Activity 
{
	private static final int TAKE_AVATAR_DEFAULT_GALLERY_REQUEST = 1;
	private static final int TAKE_AVATAR_USER_GALLERY_REQUEST = 2;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.search);		

		final String[] items = 
		{
				getResources().getString(R.string.default_avatar),
				getResources().getString(R.string.user_avatar),
		};

		class CustomImageAdapter extends ArrayAdapter<String> 
		{

			public CustomImageAdapter(Context context, int textViewResourceId, String[] objects) 
			{
				super(context, textViewResourceId, objects);
				// TODO Auto-generated constructor stub
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) 
			{
				// TODO Auto-generated method stub
				// return super.getView(position, convertView, parent);
				View row = convertView;

				if(row==null)
				{
					LayoutInflater inflater=getLayoutInflater();
					row=inflater.inflate(R.layout.search_items, parent, false);
				}

				TextView label=(TextView)row.findViewById(R.id.UsernameResults);
				label.setText(items[position]);
				ImageView icon=(ImageView)row.findViewById(R.id.UserIconResults);
				return row;
			}
		}
		ListView resultsList = (ListView) findViewById(R.id.ListViewResults);
		resultsList.setAdapter(new CustomImageAdapter(AppSandSearchDialogActivity.this, R.layout.search, items));
	

	resultsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
	{ 
		public void onItemClick(AdapterView<?> parent,View itemClicked,int position,long id) 
		{
		// TODO Auto-generated method stub
		//super.onListItemClick(l, v, position, id);
		}});
	}
}
base xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/black">
	
	<LinearLayout 
    	android:orientation="horizontal"
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:background="@android:color/black">
	
		<EditText 
			android:text="@+id/EditText01" 
			android:id="@+id/EditTextSearchText" 
			android:layout_width="fill_parent" 
			android:layout_height="wrap_content">
		</EditText>
	
		<ImageButton 
			android:id="@+id/ImageButtonSearchButton" 
			android:layout_width="wrap_content" 
			android:layout_height="wrap_content">
		</ImageButton>
	</LinearLayout>				
	
	<LinearLayout
		android:background="@android:color/white"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content">
	
		<ListView
    		android:layout_height="wrap_content"
        	android:id="@+id/ListViewResults"
        	android:layout_width="fill_parent"
        	android:divider="?android:attr/listDivider"
        	android:dividerHeight="4px"
        	android:layout_alignParentTop="true">
		</ListView>
	</LinearLayout>
</LinearLayout>
items xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="horizontal"
	android:paddingTop="10dp"
	android:paddingLeft="10dp"
	android:paddingRight="10dp"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:background="@android:color/white">    
    
    <ImageView 
		android:id="@+id/UserIconResults"
		android:src="@drawable/icon"
		android:layout_width="50dp"
		android:layout_height="50dp"/>	    
    
	<TextView 
		android:id="@+id/UsernameResults"
		android:paddingTop="15dp"
		android:paddingLeft="15dp"
		android:gravity="center_vertical"
		android:layout_gravity="center_horizontal"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:textSize="15px" 
		android:text="text"
		android:textColor="@android:color/black"/>	
</LinearLayout>
awmayhall is offline  
Reply With Quote
Reply

Bookmarks

Tags
adapter, android dialog, custom adapter, custom dialog, dialog box, listactivity, search, search box


Go Back   Android Forums > Android Discussion > Android Lounge User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a ListView in a Dialog kiranuday43 Application Development 5 October 28th, 2011 10:07 AM
Help With Dialog title alignment rbhdroid Application Development 0 December 22nd, 2010 04:41 PM
Support SMS Dialog Box RageXicity LG Ally 0 September 28th, 2010 01:29 AM
complete action using dialog iduke Application Development 0 March 10th, 2010 02:03 PM
Settings Dialog Bodom Application Development 5 July 9th, 2009 12:00 PM



All times are GMT -5. The time now is 09:54 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo