Hello, this is my first post.
Im Rick, but ill introduce myself later in that part of the forum,
i just started trying to learn to develop android apps, so i hope someone can be so nice to help me, it would be appreciated.
I am trying to do the gridview tutorial from developer.android.com
I've been busy with it for quite a while now but i can't figure out why it wont work.....
This is my 3rd app (from a tutorial, the hello tut's...)
First i had a lot of errors but after doing some Google-ing, i cleared those away by putting // in front of import android.R;
Like this //import android.R;
But now when i try to run my app, it tells me that my project still contains errors, and that i need to fix them.
I've searched but i cant find the error (eclipse wont show them either...)
All i did was instead of using the example images is use my own....
But i dont see why that should make the difference, all i modified was the name thats it.
Those image names are given on the very last part of the code if you want to check it out.
Also, the images are in the drawable folder!
and it is setup as an android app....
And here is the main.xml file if needed...
Im Rick, but ill introduce myself later in that part of the forum,
i just started trying to learn to develop android apps, so i hope someone can be so nice to help me, it would be appreciated.
I am trying to do the gridview tutorial from developer.android.com
I've been busy with it for quite a while now but i can't figure out why it wont work.....
This is my 3rd app (from a tutorial, the hello tut's...)
First i had a lot of errors but after doing some Google-ing, i cleared those away by putting // in front of import android.R;
Like this //import android.R;
But now when i try to run my app, it tells me that my project still contains errors, and that i need to fix them.
I've searched but i cant find the error (eclipse wont show them either...)
All i did was instead of using the example images is use my own....
But i dont see why that should make the difference, all i modified was the name thats it.
Those image names are given on the very last part of the code if you want to check it out.
Also, the images are in the drawable folder!
and it is setup as an android app....
Code:
package com.rickynldev.hellogridview;
//import android.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class HelloGridView extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.foto1, R.drawable.foto2,
R.drawable.foto3, R.drawable.foto4,
R.drawable.foto5, R.drawable.foto6,
R.drawable.foto7, R.drawable.foto8,
R.drawable.foto9, R.drawable.foto10,
R.drawable.foto11, R.drawable.foto12,
R.drawable.foto13, R.drawable.foto14,
R.drawable.foto15, R.drawable.foto16,
R.drawable.foto17, R.drawable.foto18,
R.drawable.foto19, R.drawable.foto20,
R.drawable.foto21, R.drawable.foto22
};
}
}
And here is the main.xml file if needed...
Code:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>