AutoCompleteTextView Items and Redirecting Layout. Help!

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

AutoCompleteTextView Items and Redirecting Layout. Help!

Postby Madz » Mon Sep 15, 2008 1:34 pm

Hi,

I'm new in Android and I've got 2 questions.

First, the idea is to have the AutoCompleteTextView items in XML format other than String Array.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String[] Animals = new String[] {
  2.  
  3.                 "Cat", "Dog", ...
  4.  
  5.         };
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Is there a way how can I populate the ArrayAdapter using an XML formatted items somewhat like
this.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <resources>
  3.  
  4.     <array name="Animals">
  5.  
  6.         <item>Cat</item>
  7.  
  8.         <item>Dog</item>
  9.  
  10.         <item>...</item>
  11.  
  12.     </array>
  13.  
  14. </resources>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I know that this format works in ListView but how could I achieve like this in AutoCompleteTextView.

Second, when a user choose and click(using the Center Button) from the AutoCompleteTextView the user will be redirect in a separate layout. So far this two doesn't work in me and I don't have any idea how I can redirect the user to view other layout?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. textView.setOnItemClickListener(new OnItemClickListener() {
  2.  
  3.  
  4.  
  5.                         @Override
  6.  
  7.                         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
  8.  
  9.                                         long arg3) {
  10.  
  11.                                 if( textView.getText().toString().equals("Dog") )  {
  12.  
  13.                                          // seperate layout view
  14.  
  15.                                         //Image of a Dog
  16.  
  17.                                 }
  18.  
  19.                         }
  20.  
  21.  
  22.  
  23.                 });
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Or

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. textView.setOnItemSelectedListener( new OnItemSelectedListener() {
  2.  
  3.  
  4.  
  5.                         @Override
  6.  
  7.                         public void onItemSelected(AdapterView<?> arg0, View arg1,
  8.  
  9.                                         int arg2, long arg3) {
  10.  
  11.                                 if( textView.getText().toString().equals("Dog") )  {
  12.  
  13.                                        // seperate layout view
  14.  
  15.                                        //Image of a Dog
  16.  
  17.                                 }
  18.  
  19.                         }
  20.  
  21.  
  22.  
  23.                         @Override
  24.  
  25.                         public void onNothingSelected(AdapterView<?> arg0) {
  26.  
  27.                                 // TODO Auto-generated method stub
  28.  
  29.  
  30.  
  31.                         }
  32.  
  33.  
  34.  
  35.                 });
  36.  
  37.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


If the condition was meet then it should redirect the user from another layout somewhat like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <ImageView
  2.  
  3.            android:src="@drawable/Dog.jpg"
  4.  
  5.            android:layout_width="wrap_content"  />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Hoping someone can help me.
Thanks in advance and more power to the Anddev Community.
Madz
Freshman
Freshman
 
Posts: 3
Joined: Mon Sep 15, 2008 12:42 pm

Top

Postby plusminus » Mon Sep 15, 2008 9:50 pm

Hello madz,

I have no code-access here, but there should be something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String[] arr = getResources().getStringArray(R.array.mzArray);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

and have a look for ArrayAdapter which has a lot of constructors you could use:

ArrayAdapter(Context context, int textViewResourceId)
ArrayAdapter(Context context, int resource, int textViewResourceId) <-- probably this one is your choice
ArrayAdapter(Context context, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)


In the OnItemClickListener.onItemClick you could launch a new Activity which takes a really simple layout and pass the resource-id (like [font=Courier New]R.drawable.dogimage[/font] ) along with the intent you use for starting that activity.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests