How to realise a Grid of Views..?

Put your problem here if it does not fit any of the other categories.

Postby plusminus » Sun Feb 03, 2008 10:42 pm

Hello sommeralex,

"linearity" can be horizontal or vertical. Horizontal is the default for Linearlayout.

Add the following line :darrow: to the constructor to make it Vertical:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.setOrientation(LinearLayout.VERTICAL);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


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

Postby sommeralex » Sun Feb 03, 2008 11:03 pm

thx!!

but - oh my god - i mixed the meaning of horizontal with vertical (i mean i know whats hor/ver) ;-)

but, i thought, if something is set to horizontal, a view then is like this

---------
a
---------
b
---------
c
---------

and if the elements are added, they come for each "addView"invocation in the next line. But, horizontal means

--- a--- b--- c ----

so, its an little excuse (that i really read the doc but just was confused about the result)
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby sommeralex » Mon Feb 04, 2008 12:01 am

hello plusminus,

how can i make exactley the menu you are showing in the screenshot? (the screenshot and example you sent are not the same..)

A Grid View for me is something like a (dynamic) table -> i want each icon i add, to be positioned the same as in your screenshot. But which funtciton is responsible for this?

each iconText needs the full screen-line-space.. i can senter them, or align them to left, but i only have for each row one view object.

hm..

i got a sollution but i am not really happy about it:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4.  
  5.  
  6. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.    android:orientation="horizontal"
  9.  
  10.    android:layout_width="fill_parent"
  11.  
  12.    android:layout_height="fill_parent"
  13.  
  14.    >
  15.  
  16. <GridView id="@+id/myGrid"
  17.  
  18.         android:layout_width="fill_parent"
  19.  
  20.         android:layout_height="fill_parent"
  21.  
  22.      android:numColumns="3"
  23.  
  24.     /> 
  25.  
  26. </LinearLayout>
  27.  
  28.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


android:numColumns="3" -> works, but i would prefer auto_fit like

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. android:numColumns="auto_fit"
  3.  
  4.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


but then, i have a division by null error (?)
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Mon Feb 04, 2008 1:50 am

Hello sommeralex,

oh sorry, i changed the onCreate() (after I zipped the code) to get a nicer screenshot:
This is what it finally looked like:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         protected void onCreate(Bundle icicle) {
  3.                 super.onCreate(icicle);
  4.  
  5.                 setContentView(R.layout.iconmenu);
  6.  
  7.                 iconTextGrid = (GridView) findViewById(R.id.myGrid);
  8.                 iconTextGrid.setNumColumns(3);
  9.                 IconTextMenuAdapter itma = new IconTextMenuAdapter(this);
  10.  
  11.                 itma.add(new IconTextMenuView(this, "Menu 1"));
  12.                 itma.add(new IconTextMenuView(this, "Menu 2"));
  13.                 itma.add(new IconTextMenuView(this, "Menu 3"));
  14.                 itma.add(new IconTextMenuView(this, "Menu 4"));
  15.                 itma.add(new IconTextMenuView(this, "Menu 5"));
  16.                 itma.add(new IconTextMenuView(this, "Menu 6"));
  17.                 itma.add(new IconTextMenuView(this, "Menu 7"));
  18.                 itma.add(new IconTextMenuView(this, "Menu 8"));
  19.                 itma.add(new IconTextMenuView(this, "Menu 9"));
  20.  
  21.                 iconTextGrid.setAdapter(itma);
  22.         }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


GridViews like in Swing are filled primary from left to right, and secondary from top to bottom. I don't know how these rules can be broken.

The " android:numColumns="auto_fit" " would be really useful, but also doesn't work with me.
Throws an internal Exception, what is probably not our fault(Tried it with my AndNav-FlagGrid):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. E/AndroidRuntime(563):     at android.widget.GridView.determineColumns(GridView.java:536)
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Last edited by plusminus on Mon Feb 04, 2008 12:01 pm, edited 1 time in total.
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 sommeralex » Mon Feb 04, 2008 11:12 am

hello plusminus,

what if there is not enough space on the phone due to the use of 3 columns?
is the auto_fit bug mentioned as a bug at google? ( i couldnt find it in the list ->because if so, i will put it in the bug list)
alex
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Mon Feb 04, 2008 12:01 pm

Hello sommeralex,

thats the reason why the "auto-fit" exists, but it does not yet work correctly.

:arrow: I've put the issue to the tracker.
Just approved that it also happens with xml-only layout (without Adapter-Stuff):
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. <GridView
  8.         android:layout_width="wrap_content"
  9.         android:layout_height="wrap_content"
  10.         android:numColumns="auto_fit">
  11.                  <Button android:layout_width="wrap_content"
  12.      android:layout_height="wrap_content" android:text="Test" />
  13.          <Button android:layout_width="wrap_content"
  14.      android:layout_height="wrap_content" android:text="Test" />
  15.          <Button android:layout_width="wrap_content"
  16.      android:layout_height="wrap_content" android:text="Test" />
  17.          <Button android:layout_width="wrap_content"
  18.      android:layout_height="wrap_content" android:text="Test" />
  19.          <Button android:layout_width="wrap_content"
  20.      android:layout_height="wrap_content" android:text="Test" />
  21.          <Button android:layout_width="wrap_content"
  22.      android:layout_height="wrap_content" android:text="Test" />
  23.          <Button android:layout_width="wrap_content"
  24.      android:layout_height="wrap_content" android:text="Test" />
  25. </GridView>
  26. </LinearLayout>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


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

Postby sommeralex » Mon Feb 04, 2008 12:40 pm

ok! thx :wink:
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby sommeralex » Sat Feb 23, 2008 7:14 pm

hello nice forum ;-)

the iconMenu was a little challenge! the next thing to do would be to implement a "real icon menu" as described now: The trouble is, that this version now only is usable with the mouse/touch. - but what about mobile phones without a touchscreen?

how can i make make view (which containts of views) being "selectable" with KEY? and if it is selected, i want some graphical action (select-status)

hope, some can help me..

i think, it has something to do with:
Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus().

alex
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby E.Jyothsna » Wed Apr 09, 2008 3:32 pm

by using grid view how can we click that icons using emulator keys?by using mouse its working.but i want to display by using emulator keys.plz reply me soon.it's very urgent.
E.Jyothsna
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Feb 28, 2008 12:25 pm
Location: chennai

Postby Beachy » Tue Dec 09, 2008 2:19 am

not really a quick reply but here you go...

where you set up your grid,

mGrid.setOnItemClickListener(mGridCardClickListener);




// for when we click on an object in the grid
AdapterView.OnItemClickListener mGridCardClickListener = new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
someClickAction((ImageView) v);
}
};

// just an example as if the items in your grid are ImageViews...
Beachy
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Dec 09, 2008 2:11 am

Re: How to realise a Grid of Views..?

Postby mithat » Thu Jan 27, 2011 4:14 am

hello all :D
mithat
Junior Developer
Junior Developer
 
Posts: 14
Joined: Thu Jul 29, 2010 5:05 pm

Top
Previous

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 20 guests