Grid View Tutorial

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Grid View Tutorial

Postby discodowney » Tue Mar 15, 2011 3:53 pm

So i used Java alot during college and the first year and a half of my last job. Right now im going through some tutorials. Im on the Grid Layout: http://developer.android.com/resources/ ... dview.html.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle savedInstanceState) {
  2.     super.onCreate(savedInstanceState);
  3.     setContentView(R.layout.main);
  4.  
  5.     GridView gridview = (GridView) findViewById(R.id.gridview);
  6.     gridview.setAdapter(new ImageAdapter(this));
  7.  
  8.     gridview.setOnItemClickListener(new OnItemClickListener() {
  9.         public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
  10.             Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
  11.         }
  12.     });
  13. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Ive never seen anything like the last part. onItemClick is a predefined method in the Android sdk. So why do you need to specify the parameter list? Is it like a delegate function in C#?

EDIT: a question more about the tutorial, if anyone knows the answer. But why at the end in the ThumbsId array are there three copies of each number?

Im also having a problem. The app starts, but the pictures do not come up. Ive tried saving the pictures to all three res/drawable folders but it makes no difference. I assume in R.java i have to associate each picture with one of the R.drawable.sample_x's? Is that right? If not anyone know where i might be going wrong?

Cheers
discodowney
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Mar 02, 2011 3:10 pm

Top

Re: Grid View Tutorial

Postby blundell » Tue Mar 15, 2011 4:45 pm

Your onItemClick listener is an Anonymous Inner Class where your using only one method the onItemClick.

Thumbs array - dunno

R.java is automatically generated and should make these associations automatically. Check your console or logcat for errors.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Grid View Tutorial

Postby discodowney » Tue Mar 15, 2011 7:45 pm

Whats my logcat?

My console says nothing really:

Android Launch!
[2011-03-15 18:51:14 - HelloGridView] adb is running normally.
[2011-03-15 18:51:14 - HelloGridView] Performing test.gridview.HelloGridView activity launch
[2011-03-15 18:51:14 - HelloGridView] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD '2.1AVD'
[2011-03-15 18:51:16 - HelloGridView] Application already deployed. No need to reinstall.
[2011-03-15 18:51:16 - HelloGridView] Starting activity test.gridview.HelloGridView on device emulator-5554
[2011-03-15 18:51:18 - HelloGridView] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=test.gridview/.HelloGridView }

Its strange, when i click the squares where the photos would be it seems like they are there, they just arent displaying. When i click the area, the square highlights and the action that should happen when i click a photo, according to the code, executes. Its weird.
discodowney
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Mar 02, 2011 3:10 pm

Re: Grid View Tutorial

Postby blundell » Tue Mar 15, 2011 10:02 pm

Logcat is where all your error's are shown! Jesas man :p

Eclipse > Window > Open Perspective > Other... > DDMS

http://developer.android.com/guide/deve ... index.html
http://developer.android.com/guide/deve ... ogcat.html
http://developer.android.com/guide/deve ... /ddms.html
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 2 guests