Hi Kavitha,
Thanks for the reply. Samething I tryied, i wrote like this :
grid_main.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int
position, long id) {
if(position==0){
Intent intent1 = new Intent(latest_icon_droid.this,
screen.class);
startActivity(intent1);
}
}
});
But then also, it is considering all the images are with position 0.
So when i clicked on any item, it is displaying the second screen,
which is not supposed to be displayed. :-(
Any idea, why is it like this?
On Mar 22, 4:32 pm, kavitha sunil <[email protected]> wrote:
> I think you can check the item that is clicked using the position param in
> the function onItemClick() and if it is the first item
> only then call start activity,. Don't call for each item click. This should
> help./
>
> On Mon, Mar 22, 2010 at 4:22 PM, NewDev <[email protected]> wrote:
>
> > Hi,
>
> > I am trying to write an application where I am trying to display
> > images along with the texts for the same. Images are displayed
> > properly on the grid.
>
> > Now I have one second screen, wherein On clicking only on the first
> > image, the seccond screen1 should be displayed. But now whats
> > happening is clicking on second, third, fourth and so on, images also
> > the same secocnd screen1 is displayed. I want to display the second
> > screen1 only if user clicks on first image. Could anybody please look
> > in to this and let me know where i am going wrong.
>
> > I have copied my files for your reference. I am using GridView for
> > displaying images and absolute layout for the texts for the images.
>
> > Thanks,
>
> > package com.android.latest_icon_droid;
>
> > 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.Button;
> > import android.widget.GridView;
> > import android.widget.ImageView;
> > import android.widget.TextView;
> > import android.widget.Toast;
> > import android.content.Intent;
> > import android.widget.AdapterView.OnItemClickListener;
> > import android.widget.*;
> > import android.view.LayoutInflater;
>
> > public class latest_icon_droid extends Activity {
> > /** Called when the activity is first created. */
> > GridView grid_main;
> > �...@override
> > public void onCreate(Bundle savedInstanceState) {
> > super.onCreate(savedInstanceState);
> > setContentView(R.layout.main1);
> > grid_main = (GridView)findViewById(R.id.GridView01);
> > grid_main.setAdapter(new ImageAdapter(this));
>
> > grid_main.setOnItemClickListener(new OnItemClickListener() {
> > public void onItemClick(AdapterView<?> parent, View v, int
> > position, long id) {
>
> > Intent intent1 = new Intent(latest_icon_droid.this,
> > screen.class);
> > startActivity(intent1);
>
> > }
> > });
>
> > }
> > public class ImageAdapter extends BaseAdapter{
> > //Context mContext;
> > //public static final int ACTIVITY_CREATE = 10;
> > public ImageAdapter(Context c){
> > mContext = c;
> > }
> > // �...@override
> > public int getCount() {
> > return mThumbIds.length;
>
> > }
>
> > public Object getItem(int position) {
> > // return null;
> > return position;
> > }
>
> > public long getItemId(int position) {
> > // return 0;
> > return position;
> > }
>
> > // //@Override
> > public View getView(int position, View convertView, ViewGroup
> > parent) {
>
> > View v;
> > ImageView imageView;
> > if(convertView==null){
> > imageView = new ImageView(mContext);
> > imageView.setLayoutParams(new GridView.LayoutParams(45,
> > 45));
> > imageView.setAdjustViewBounds(false);
>
> > imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
> > imageView.setPadding(5, 5, 5, 5);
> > LayoutInflater li = getLayoutInflater();
> > v = li.inflate(R.layout.main, null);
> > }
> > else
> > {
> > v = convertView;
> > //imageView = (ImageView) convertView;
> > }
>
> > TextView tv =
> > (TextView)v.findViewById(R.id.icon_text1);
> > ImageView iv =
> > (ImageView)v.findViewById(R.id.icon_image1);
> > iv.setImageResource(mThumbIds[0]);
>
> > TextView tv1 =
> > (TextView)v.findViewById(R.id.icon_text2);
> > ImageView iv1 =
> > (ImageView)v.findViewById(R.id.icon_image2);
>
> > iv1.setImageResource(mThumbIds[1]);
>
> > TextView tv2 =
> > (TextView)v.findViewById(R.id.icon_text3);
> > ImageView iv2 =
> > (ImageView)v.findViewById(R.id.icon_image3);
>
> > iv2.setImageResource(mThumbIds[2]);
>
> > TextView tv3 =
> > (TextView)v.findViewById(R.id.icon_text4);
> > ImageView iv3 =
> > (ImageView)v.findViewById(R.id.icon_image4);
>
> > iv3.setImageResource(mThumbIds[3]);
>
> > TextView tv4 =
> > (TextView)v.findViewById(R.id.icon_text5);
> > ImageView iv4 =
> > (ImageView)v.findViewById(R.id.icon_image5);
>
> > iv4.setImageResource(mThumbIds[4]);
>
> > TextView tv5 =
> > (TextView)v.findViewById(R.id.icon_text6);
> > ImageView iv5 =
> > (ImageView)v.findViewById(R.id.icon_image6);
>
> > iv5.setImageResource(mThumbIds[5]);
>
> > TextView tv6 =
> > (TextView)v.findViewById(R.id.icon_text7);
> > ImageView iv6 =
> > (ImageView)v.findViewById(R.id.icon_image7);
>
> > iv6.setImageResource(mThumbIds[6]);
>
> > TextView tv7 =
> > (TextView)v.findViewById(R.id.icon_text8);
> > ImageView iv7 =
> > (ImageView)v.findViewById(R.id.icon_image8);
>
> > iv7.setImageResource(mThumbIds[7]);
>
> > TextView tv8 =
> > (TextView)v.findViewById(R.id.icon_text9);
> > ImageView iv8 =
> > (ImageView)v.findViewById(R.id.icon_image9);
>
> > iv8.setImageResource(mThumbIds[8]);
>
> > return v;
> > }
> > private Context mContext;
>
> > private Integer[] mThumbIds = {
> > R.drawable.sample1, R.drawable.sample2,
> > R.drawable.sample3, R.drawable.sample4,
> > R.drawable.sample5, R.drawable.sample6,
> > R.drawable.sample7, R.drawable.sample8,
> > R.drawable.sample9,
>
> > };
>
> > }
>
> > }
>
> > main.xml
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <AbsoluteLayout
> > android:id="@+id/widget98"
> > android:layout_width="fill_parent"
> > android:layout_height="fill_parent"
> > xmlns:android="http://schemas.android.com/apk/res/android"
> > android:layout_x="100px"
> > android:layout_y="100px"
> > android:gravity="center_horizontal"
> > android:background="@drawable/background"
>
> > <ImageView
> > android:id="@+id/icon_image1"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="30px"
> > android:layout_y="30px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text4"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text1"
> > android:layout_x="35px"
> > android:layout_y="205px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image2"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="115px"
> > android:layout_y="30px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text2"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text2"
> > android:layout_x="100px"
> > android:layout_y="95px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image3"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="200px"
> > android:layout_y="30px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text3"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text3"
> > android:layout_x="200px"
> > android:layout_y="95px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image7"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="30px"
> > android:layout_y="240px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text1"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text4"
> > android:layout_x="20px"
> > android:layout_y="95px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image5"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="115px"
> > android:layout_y="140px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text5"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text5"
> > android:layout_x="120px"
> > android:layout_y="205px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image6"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="200px"
> > android:layout_y="140px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text6"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text6"
> > android:layout_x="205px"
> > android:layout_y="205px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image4"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="30px"
> > android:layout_y="140px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text7"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text7"
> > android:layout_x="30px"
> > android:layout_y="305px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image8"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:layout_x="115px"
> > android:layout_y="240px"
>
> > </ImageView>
> > <TextView
> > android:id="@+id/icon_text8"
> > android:layout_width="wrap_content"
> > android:layout_height="wrap_content"
> > android:text="text8"
> > android:layout_x="120px"
> > android:layout_y="305px"
> > android:textColor="#000000"
>
> > </TextView>
> > <ImageView
> > android:id="@+id/icon_image9"
>
> ...
>
> read more »
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe from this group, send email to
android-developers+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.