Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Android 4 Application Development
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Android 4 Application Development
This is the forum to discuss the Wrox book Beginning Android 4 Application Development by Wei-Meng Lee; ISBN: 978-1-1181-9954-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Android 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 24th, 2013, 06:22 PM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 5 page 220 Gallery Spinner JAR Source Not Found.

Hello there Wrox users and authors! I have run in to quite a predicament here. I am making the scroll gallery in chapter 5 and every time It starts up its fine. Click on a picture, fine. Scroll between the pictures that are visible or partially visible (the first 3) is fine. Just when I try to scroll to any picture thats not already visible on start up is when it all crumbles. It will freeze up the emulator then, back in eclipse it goes to a tab that says "The JAR file has no source attachment" I have redone this code three times and it still does this. Here is the code for main.xml.

Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".GalleryActivity" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Images of San Francisco" />

      <Gallery
        android:id="@+id/gallery1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    
    <ImageView
        android:id="@+id/image1"
        android:layout_width="320dp"
        android:layout_height="250dp"
        android:scaleType="fitXY" />

</LinearLayout>
Here is for attrs

Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>
Here is for GalleryActivity.java

Code:
package net.learn2develop.Gallery;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;

public class GalleryActivity extends Activity {
	Integer[] imageIDs = {
			R.drawable.pic1,
			R.drawable.pic2,
			R.drawable.pic3,
			R.drawable.pic4,
			R.drawable.pic5,
			R.drawable.pic6,
			R.drawable.pic7
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	
	Gallery gallery = (Gallery) findViewById(R.id.gallery1);
	
	gallery.setAdapter(new ImageAdapter(this));
	gallery.setOnItemClickListener(new OnItemClickListener()
	{
		public void onItemClick(AdapterView parent, View v,
				int position, long id)
		{
			Toast.makeText(getBaseContext(),
					"pic" + (position + 1) + " selected",
							Toast.LENGTH_SHORT).show();
		}
	});
}

public class ImageAdapter extends BaseAdapter
{
	Context context;
	int itemBackground;
	
	public ImageAdapter(Context c)
	{
		context = c;
		TypedArray a = obtainStyledAttributes(
				R.styleable.Gallery1);
		itemBackground = a.getResourceId(
				R.styleable.Gallery1_android_galleryItemBackground,
				0);
		a.recycle();
	}
	
	public int getCount() {
		return imageIDs.length;
	}
	
	public Object getItem(int position) {
		return position;
	}
	
	public long getItemId(int position) {
		return position;
	}
	
	public View getView(int position, View convertView,
			ViewGroup parent) {
		ImageView imageView;
		if (convertView == null) {
			imageView = new ImageView(context);
			imageView.setImageResource(imageIDs[position]);
			imageView.setScaleType(
					ImageView.ScaleType.FIT_XY);
			imageView.setLayoutParams(
					new Gallery.LayoutParams(150, 120));
		} else {
			imageView = (ImageView) convertView;
		}
		imageView.setBackgroundResource(itemBackground);
		return imageView;
	}
	
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.gallery, menu);
		return true;

	}
}
}
What is going on? If someone could enlighten me it would be very much appreciated!

Caden11998,
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"android.jar Source Not Found" Caden3208 BOOK: Beginning Android 4 Application Development 0 March 12th, 2013 10:19 PM
Chapter 8: Gallery Gudni BOOK: Beginning ASP.NET Web Pages with WebMatrix 1 February 13th, 2012 05:20 PM
Chapter 5 - Gallery.setAdapter() androider BOOK: Beginning Android Application Development 0 June 29th, 2011 12:16 PM
Source Not found error in Chapter 4 soclose BOOK: Professional Android 2 Application Development 2 April 26th, 2010 06:11 AM
Wrox Photo Gallery In C# Source Code Sojan80 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 16 May 13th, 2008 03:01 AM



All times are GMT -4. The time now is 11:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.