Iconified TextList - The making of

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

Postby plusminus » Wed Feb 27, 2008 5:26 pm

Hello rahul,

since m5 there is an Expandable List built in:

ExpandableListView:

  • android.widget.ExpandableListView is a new widget that provides a two-level tree-type widget. The top-level items are groups and are each expandable/collapsible to reveal the group's children. It shows indicators (by default) to the left of each item to show the current state of the item. The indicators along with the position they should be drawn are settable.
  • The android.widget.ExpandableListAdapter provides data to this widget. It is similar to a regular Adapter, but has two sets of methods: one for groups and one for children.
    • android.widget.SimpleCursorTreeAdapter transforms Cursors to data to be used by the ExpandableListView. Do note that these Cursors must be managed by the developer (in most cases, using android.app.Activity.managedQuery()), however the adapter may choose to deactivate a Cursor prior to the Activity deactivating it.
    • android.widget.SimpleExpandableListAdapter transforms sets of data to be used by the ExpandableListView.
  • There is an example in the API Demos > Views > Lists > Expandable > 1, 2, 3.
  • Internally, this widget inherits from android.widget.ListView and has a connector to translate between "flat list" positions to group + child positions. Some methods will be available from ListView that return the "flat list" position, so developers should probably be aware of this. Worst case, there are methods exposed (getExpandableListPosition and getFlatListPosition) to convert between the two.
    • The expandable list position is usually represented as a "packed position" containing the type of position (either child, group, or null), and a group position (for both group and children), and a child position (for children). Methods starting with getPackedPosition... help with unpacking.


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

Thanks +/-

Postby rahul_mawkins » Wed Feb 27, 2008 5:53 pm

First you have a very helpfull site....congrats for maintaining this. Keep the good work alive

I know there is a expandable list but again its very big and takes up lot of space on screen
But guess we have no other choice left out on this

Thanks again
Rahul
rahul_mawkins
Developer
Developer
 
Posts: 34
Joined: Wed Feb 27, 2008 4:09 am

Postby plusminus » Thu Feb 28, 2008 2:14 am

Hello rahul,

I would rely on all Android-included widgets as far as possible.

Google knows what they are doing and why they are doing it that way.

Yes, since m5 everything is a bit large (current m5-version gui was designed for HVGA, expect changes/improvements especially for QVGA in the next releases).

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

Postby qamerfarooq » Thu Feb 28, 2008 3:31 pm

Has someone tried to use ViewBinder with SimpleCursorAdapter to replace the custom IconifiedTextListAdapter class?

ViewBinder is provided in the new SDK M5.
Qamer Farooq
End 2 End Solution Providers
http://www.e2esp.com
qamerfarooq
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jan 11, 2008 6:07 am
Location: Pakistan

Postby mawa » Thu Feb 28, 2008 10:24 pm

manmath wrote:This is a Very useful tutorial.
Can we modify the design as shown below ?

IconifiedTextListAdapter itla= new IconifiedTextListAdapter(Context, <row layout.xml>, <drawable array>, <String array>)
setListAdapter(itla);

I guess this is the standard way Arrayadapter is used.
While implementing the above design, i am not able to create a layout out of rowlayout.xml in the file IconifiedTextView.java..
Which API can be used to get the layout object out of .xml?
Can anybody suggest the solution for this type of implementation ?



Thanks in advance


I have the same interest as manmath. How does it work, if the layout of the iconifiedTextList is described by XML ? I played around with it the last days, but without success.

Like the notepad sample (tutorial exercise), I created two XML files, one for the ListView and one for the rows. Can someone give me a hint, how to get the row_layout.xml in method #getView of my custom adapter. I always get a NullPointerException when using findViewById(R.layout.row_layout).

Every help is welcome.

BTW Many thanks for providing such helpful tutorials. Good work :)
mawa
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 27, 2008 9:59 am
Location: Germany

There is no way

Postby rahul_mawkins » Thu Feb 28, 2008 10:39 pm

Your row_layout.xml should exactly match what comes out of getView method
In tutorial they are smart enough to get the away by simple text field but if you have a very complex layout
please make God sit with you.
I am facing someway a similar problem but guess we have no other choice
Again may be there is a way but I am not sure
rahul_mawkins
Developer
Developer
 
Posts: 34
Joined: Wed Feb 27, 2008 4:09 am

Top

may be this may work

Postby rahul_mawkins » Thu Feb 28, 2008 10:58 pm

for getting a reference to a view you may have a global variable in activity class that holds the reference to those view
for eg

public class MyStupidList extends ListActivity
{
private MyComplicatedView mcv;
//complicated view consist of textview and lower child view which is some other comlicated view
private TextView tv;
private ChildComplicatedView ccv;
//this contains many other stuff


oncreate(Bundle).....
setContentView(R.layout.start_screen);

//get hold of every child down here
rahul_mawkins
Developer
Developer
 
Posts: 34
Joined: Wed Feb 27, 2008 4:09 am

DO somebody knows this

Postby rahul_mawkins » Fri Feb 29, 2008 12:18 am

Like I said I have a List which consist of List activity
So I can have a xml layout as

<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- <TextView android:id="@+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Notes!"/> -->
<view class="com.android.myprog.MyView"
android:id="@+id/Myview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>


Now Myview extends a table layout and is a seprate class
now my question is if I can express MyView in xml then how will I render the view

There is no method as setContentView when it comes to MyView extends TableLayout

Any idea???
rahul_mawkins
Developer
Developer
 
Posts: 34
Joined: Wed Feb 27, 2008 4:09 am

Postby code » Mon Mar 10, 2008 10:44 pm

Thanks plusminus for this tutorial :D
It was very helpfull for me and I created my own List and it looked very nice ^^ and am trying to create more custome lists based on your tutorial

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

Postby rmeph » Wed Mar 12, 2008 2:49 pm

can we change selected text color ????what method will be use?
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby code » Thu Mar 13, 2008 9:39 am

hi rmeph,

I did similar thing and change some propertites of the selected row. For this I override 'onKeyUp' & 'onKeyDown' methods. Maybe there is another way :) but this what I used.
User avatar
code
Junior Developer
Junior Developer
 
Posts: 21
Joined: Sat Feb 09, 2008 6:24 pm
Location: UAE

Postby rmeph » Mon Mar 24, 2008 10:07 am

code wrote:hi rmeph,

I did similar thing and change some propertites of the selected row. For this I override 'onKeyUp' & 'onKeyDown' methods. Maybe there is another way :) but this what I used.


plz give some example how to do it????
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby code » Tue Mar 25, 2008 9:25 am

hi rmeph,

I am not sure if this is correct or not :roll: but it works for me.
Here is a saample:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. @Override
  5.  
  6.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  7.  
  8.                
  9.  
  10.                 if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
  11.  
  12.                 // write the codes for thactions you want to see - e.g change text color
  13.  
  14.                 }
  15.  
  16.                 if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
  17.  
  18.                 // write the codes for thactions you want to see - e.g change text color
  19.  
  20.                 }
  21.  
  22.  
  23.  
  24.                 return super.onKeyDown(keyCode, event);
  25.  
  26.         }
  27.  
  28.  
  29.  
  30.  
Parsed in 0.031 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

possible to use imageview instead of a drawable?

Postby androidonkey » Fri Apr 04, 2008 7:45 am

Hi +/-,

Is it possible to use an imageview instead of a drawable in the iconifiedtextview above?

For example, instead of:
IconifiedText bt1 = new IconifiedText("Surf Web",getResources().getDrawable(R.drawable.favicon));

Use this (I'm creating an imageview from a url using your very useful code example):
ImageView i = new ImageView(this);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(36, 36));
try {
/* Open a new URL and get the InputStream to load data from it. */
URL aURL = new URL(FriendPicList[0]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
/* Apply the Bitmap to the ImageView that will be returned. */
i.setImageBitmap(bm);
} catch (IOException e) {
//i.setImageResource(R.drawable.error);
Log.e("DEBUGTAG", "Remote Image Exception", e);
}

IconifiedText bt1 = new IconifiedText("Surf Web",i);


If it is possible, what adjustments to the custom listadapter and textview would have to be changed?

Thanks.
androidonkey
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Feb 18, 2008 10:20 am

Postby ferobert » Sun Apr 06, 2008 6:33 pm

Hi code

In which class did you add your onKeyDown() method? I added mine into the one extending ListActivity, but it fires up only when I am at the first or last row in the list. I'd like this method to be called each time I go to another row from the list (by pressing the Up/Down key), so I can alter the text within.

Please also include some code on how exactly you change the properties of the selected row.

Thanks and regards,
Robert


code wrote:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. @Override
  3.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  4.                
  5.                 if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
  6.                 // write the codes for thactions you want to see - e.g change text color
  7.                 }
  8.                 if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
  9.                 // write the codes for thactions you want to see - e.g change text color
  10.                 }
  11.  
  12.                 return super.onKeyDown(keyCode, event);
  13.         }
  14.  
  15.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
ferobert
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 06, 2008 6:22 pm

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests