Iconified TextList - The making of

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby code » Sun Apr 06, 2008 10:21 pm

Hi Robert,

First, as I mentioned before am not sure if this is the correct way for doing that or not :(
I think we must use another action listner like OnItemSelectedListener but I did not try that.

for the way I used "onKeyDown/Up" I overided these two methods in my ListActivity class. You can find an example of the way I used them in: http://www.anddev.org/video-tut_buildin ... s-t12.html

here you another example:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public boolean onKeyDown(int keyCode, KeyEvent event) {
  3.  
  4.  
  5.  
  6. if ((keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
  7.  
  8.                                 || (keyCode == KeyEvent.KEYCODE_DPAD_UP)) {
  9.  
  10.  
  11.  
  12.                         if (selectedTV != null) {
  13.  
  14.                                 dateTV.setVisibility(View.GONE);
  15.  
  16.                         }
  17.  
  18.  
  19.  
  20.                         tv =  this.getListView().getSelectedView();
  21.  
  22.                         tv.setVisibility(View.VISIBLE);
  23.  
  24.                         selectedTV = tv;
  25.  
  26.                         dateTV = (TextView) selectedTV.findViewById(2);
  27.  
  28.                         dateTV.setVisibility(View.VISIBLE);
  29.  
  30.                        
  31.  
  32.                         return true;
  33.  
  34.                 } else
  35.  
  36.                         return super.onKeyDown(keyCode, event);
  37.  
  38.         }
  39.  
  40.  
  41.  
  42.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
User avatar
code
Junior Developer
Junior Developer
 
Posts: 21
Joined: Sat Feb 09, 2008 6:24 pm
Location: UAE

Top

Postby ferobert » Mon Apr 07, 2008 4:36 pm

I think the key point is that you redefined both methods "onKeyDown/Up". I only tried with "onKeyDown", and it was triggered only at the first and last row in the list (i.e. when trying to leave the list), and not inside, when going from one row to the another. But, when I am using "onKeyUp", it works as expected.

The correct way, though, is probably as you suggested with OnItemSelectedListener. I found a complete example with this here:
http://code.google.com/android/samples/ ... List7.html
And I am using that in my code.

BTW, I posted a question for you in the thread you mentioned:
video-tut_building_an_contact-caller_app_in_minutes-t12.html

Thanks and regards,
Robert
ferobert
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 06, 2008 6:22 pm

Postby code » Mon Apr 07, 2008 9:14 pm

Thanks Robert for the example in the link :D
and this is the correct way of doing that :) thanks for sharing

Regards,
code
User avatar
code
Junior Developer
Junior Developer
 
Posts: 21
Joined: Sat Feb 09, 2008 6:24 pm
Location: UAE

Postby amitonrise » Fri Nov 21, 2008 10:55 am

Hi plusminus...
thnx for this tutorial....it really works well for me....
keep up the good work!! :wink:
amitonrise
Freshman
Freshman
 
Posts: 3
Joined: Mon Nov 10, 2008 6:58 am

Postby JoyLakh » Thu Dec 18, 2008 6:14 am

Thanks PlusMinus. This helped me a lot.

But whenever I read your quote:"Please remember, that this board is give & take", i feel a bit bad about myself, because so far I am not involved in giving process.

Thanks once again.
Celebrate Life.
JoyLakh
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Dec 16, 2008 5:42 am
Location: Bangalore, India

Postby mrsack » Tue Mar 10, 2009 2:11 am

Thanks, this is just the code I was looking for! I am getting an error in one of the files, though.

In IconifiedTextListAdapter.java at line 54:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. return super.isSelectable(position)
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Eclipse gives an error saying "The method isSelectable(int) is undefined for the type BaseAdapter." Is there a quick fix for this? Thanks!
mrsack
Freshman
Freshman
 
Posts: 9
Joined: Tue Mar 10, 2009 2:06 am

Top

Postby sentient » Mon Mar 16, 2009 4:15 pm

hey guys

real easy one: how do i get the height of the text itself within the list?

i've tried mText.getHeight() and mText.getMeasuredHeight() but they both keep returning 'null'

thanks
Do or do not, there is no try!
sentient
Freshman
Freshman
 
Posts: 8
Joined: Mon Feb 16, 2009 11:57 am
Location: London

hello everyone

Postby jackchen_he » Tue Mar 17, 2009 2:49 am

hello everyone I'm a chinese how can i get this like a project !I'm a new here! thanks!
GOOD GOOD
jackchen_he
Freshman
Freshman
 
Posts: 2
Joined: Tue Mar 17, 2009 2:33 am

HI

Postby jackchen_he » Tue Mar 17, 2009 3:33 am

mrsack wrote:Thanks, this is just the code I was looking for! I am getting an error in one of the files, though.

In IconifiedTextListAdapter.java at line 54:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. return super.isSelectable(position)
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Eclipse gives an error saying "The method isSelectable(int) is undefined for the type BaseAdapter." Is there a quick fix for this? Thanks!



just delete the super or replace by this!
GOOD GOOD
jackchen_he
Freshman
Freshman
 
Posts: 2
Joined: Tue Mar 17, 2009 2:33 am

Postby iPaul Pro » Wed Mar 25, 2009 7:30 pm

Does anyone know how to use ViewBinder with SimpleCursorAdapter to replace the custom IconifiedTextListAdapter class?

I'd like to have a relative layout with attributes like "android:layout_alignParentRight," but there are currently no related methods to use in a java file.

Any help transforming this tutorial into a XML-based layout would be greatly appreciated.

Thanks!
iPaul Pro
Developer
Developer
 
Posts: 33
Joined: Sun Mar 15, 2009 9:01 pm

Relative Layout Parameters in Java styling

Postby iPaul Pro » Sat Mar 28, 2009 4:57 pm

I figured out how to pass relative layout parameters like "android:layout_alignParentRight" to the IconifiedTextView Views.

In the IconifiedTextView.java file find:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.           mText = new TextView(context);
  2.           mText.setText(aIconifiedText.getText());
  3.           /* Now the text (after the icon) */
  4.           addView(mText, new LinearLayout.LayoutParams(
  5.                     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  6. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


In order to assign a relative parameter to "mText", we need to first assign the LayoutParams to a variable:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. LayoutParams lp = new RelativeLayout.LayoutParams(
  2.                   LayoutParams.WRAP_CONTENT,
  3.                   LayoutParams.WRAP_CONTENT);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


We then use "addRule" to assign our parameters:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. lp.addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


And finally, replace
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. addView(mText, new LinearLayout.LayoutParams(
  2.                     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

with
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. addView(mText, lp);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


IMPORTANT - You must use a NEW and UNIQUE LayoutParameter variable for every individual View.

So your new mText view declaration should look like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.          
  2.           LayoutParams lp = new RelativeLayout.LayoutParams(
  3.                   LayoutParams.WRAP_CONTENT,
  4.                   LayoutParams.WRAP_CONTENT);
  5.  
  6.           mText = new TextView(context);
  7.           mText.setText(aIconifiedText.getText());
  8.           lp.addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT);
  9.  
  10.           addView(mText, lp);
  11.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


BTW - I'm still working on converting the IconifiedListAdapter into a SimpleCursorAdapter with ViewBinder. (But in my spare time)

- iPaul Pro
iPaul Pro
Developer
Developer
 
Posts: 33
Joined: Sun Mar 15, 2009 9:01 pm

Postby iPaul Pro » Thu Apr 02, 2009 12:40 am

High-five to anyone that can tell me how to make the mText bold (or assign a bold style to any text in 'java').

I can do things like change size, color and padding like so:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mText.setPadding(5, 10, 10, 5);
  2. mText.setTextSize(16);
  3. mText.setTextColor(Color.rgb(255, 255, 204));
  4.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


But I'm not sure how to make it bold.

Thanks!

(this could be a simple enough request to be my first post to receive a reply!! Its sad, seeing as I have posted 12/13 times and anddev.org considers me a "junior developer" --- I probably just jinxed it)
iPaul Pro
Developer
Developer
 
Posts: 33
Joined: Sun Mar 15, 2009 9:01 pm

IconifiedList with XML Layout

Postby iPaul Pro » Fri Apr 03, 2009 12:06 am

Anyone interested in using an XML layout with the IconifiedTextListAdapter, try this:

Delete this (in IconifiedTextListAdapter.java):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    
  2.       /** @param convertView The old view to overwrite, if one is passed
  3.       * @returns a IconifiedTextView that holds wraps around an IconifiedText */
  4.      public View getView(int position, View convertView, ViewGroup parent) {
  5.           IconifiedTextView btv;
  6.           if (convertView == null) {
  7.                btv = new IconifiedTextView(mContext, mItems.get(position));
  8.           } else { // Reuse/Overwrite the View passed
  9.                // We are assuming(!) that it is castable!
  10.                btv = (IconifiedTextView) convertView;
  11.                btv.setText(mItems.get(position).getText());
  12.                btv.setIcon(mItems.get(position).getIcon());
  13.           }
  14.           return btv;
  15.      }
  16.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


and replace it with this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.      /** Bind our Views */
  3.      public View getView(int position, View convertView, ViewGroup parent) {
  4.          /** Inflate our Context */
  5.          LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  6.          /** Fill our Views*/
  7.          if(convertView == null) {
  8.               convertView = inflater.inflate(R.layout.list_rows, parent, false);
  9.          }     
  10.           ((TextView)convertView.findViewById(R.id.text1)).setText(mItems.get(position).getText());        
  11.           ((ImageView)convertView.findViewById(R.id.icon)).setImageDrawable(mItems.get(position).getIcon());
  12.                                                        
  13.                 return convertView;
  14.      }
  15.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


In CallLogDisplayer.java add this line directly under "super.onCreate(savedInstanceState) {"
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.main);
  2.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


You must now create a list_rows.xml file in your layout folder with the appropriate styling for R.id.text1 and R.id.icon. Your main.xml should look something like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent" >
  6.        
  7.  <ListView android:id="@android:id/list"
  8.         android:layout_width="fill_parent"
  9.         android:layout_height="fill_parent"  />
  10.        
  11.  <TextView android:id="@android:id/empty"
  12.         android:layout_width="fill_parent"
  13.         android:layout_height="fill_parent"
  14.         android:text="Nothing to display"
  15.         android:gravity="center"
  16.         android:textAppearance="?android:attr/textAppearanceLarge" />            
  17.  
  18. </LinearLayout>
  19.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Finally, clean up: delete the IconifiedTextView.java file, as it is no longer needed.

I hope this helps some people. Styling in XML is preferable in Android, as it better accommodates many api resources. I am new to Java/Android so this may not be the "correct way" or bug-proof in any way. Works well for me.

Feel free to ask me for help with this if you can't figure it out. I know how hard it is for us new guys.

- iPaul Pro
iPaul Pro
Developer
Developer
 
Posts: 33
Joined: Sun Mar 15, 2009 9:01 pm

Postby ub » Mon May 18, 2009 10:12 pm

thanks for that great tutorial...

how can I customize the listitemview corresponding to user input? I like to draw a custom background when user performs a click. how can I code this?

regards.
ub
Freshman
Freshman
 
Posts: 2
Joined: Thu May 14, 2009 3:11 pm

Postby arams » Wed May 20, 2009 7:36 am

Thanks to +Minus for doing such a great work....

I have a doubt.....

i create a iconified textview(it looks fine)...but when i am using this iconified text view to some other class the listener did not work fine....

Did u have any idea about that ....
Thanks...
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests