Android

  • Replies:6
  • OpenNot stickiedUnanswered
  • Forum posts: 7

Apr 21, 2014 5:31:44 PM via Website

Hi,

i have a Listview...click on Listitem open image and text after open full image...pls help full code..

i have a error message :Activity Not Found Exception...Pls sharing the code MainActivity.java

  • Forum posts: 7

Apr 21, 2014 5:36:58 PM via Website

i am new to this forum,am unable to insert code to this post...pls let me know how to post code..

  • Forum posts: 7

Apr 21, 2014 5:42:58 PM via Website

'MainActivity.java

package com.example.prj_10;

import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity { ListView list; String[] kkTitles; String[] kkDescriptions; int[] images={R.drawable.anamrama1,R.drawable.aruna2,R.drawable.mukesh3,R.drawable.nagendra4,R.drawable.balaraju5};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Resources res=getResources();
    kkTitles=res.getStringArray(R.array.titles);
    kkDescriptions=res.getStringArray(R.array.descriptions);

    list=(ListView) findViewById(R.id.listView1);
    MainAdapter adapter=new MainAdapter(this,kkTitles,images,kkDescriptions);
    list.setAdapter(adapter);


    GridView gridView = (GridView) findViewById(R.id.grid_view);

    // Instance of ImageAdapter Class
    gridView.setAdapter(new ImageAdapter(this));

    /**
     * On Click event for Single Gridview Item
     * */
    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), FullImage.class);
            // passing array index
            i.putExtra("id", position);
            startActivity(i);
        }
    });
}
class MainAdapter extends ArrayAdapter<String>
{
    Context context;
    int[] images;
    String[] titleArray;
    String[] descriptionArray;
    private ImageView myImage1;
    MainAdapter(Context c,String[] titles,int imgs[],String[] desc)
    {
        super(c,R.layout.activity_main,R.id.textView1,titles);
        this.context=c;
        this.images=imgs;
        this.titleArray=titles;
        this.descriptionArray=desc;

    }
    @Override
     public View getView(int position,View convertView,ViewGroup parent){
        LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.activity_main,parent,false);
        ImageView myImage1=(ImageView) row.findViewById(R.id.imageView1);
        TextView myTitle=(TextView) row.findViewById(R.id.textView1);
        TextView myDescription=(TextView) row.findViewById(R.id.textView2);
        myImage1.setImageResource(images[position]);
        myTitle.setText(titleArray[position]);
        myDescription.setText(descriptionArray[position]);

        return row;
    }

} }

ImageAdapter.Java

package com.example.prj_10;

import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter { private Context mContext;

// Keep all Images in array
public Integer[] mThumbIds = {
        R.drawable.anamrama1,

};

// Constructor
public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
    return imageView;
}

}

'

  • Forum posts: 7

Apr 21, 2014 5:46:56 PM via Website

package com.example.prj_10;

import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter { private Context mContext;

// Keep all Images in array
public Integer[] mThumbIds = {
        R.drawable.anamrama1,

};

// Constructor
public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
    return imageView;
}

}

  • Forum posts: 7

Apr 21, 2014 5:47:31 PM via Website

package com.example.prj_10;

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView;

public class FullImage extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    int position = i.getExtras().getInt("id");
    ImageAdapter imageAdapter = new ImageAdapter(this);

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view1);
    imageView.setImageResource(imageAdapter.mThumbIds[position]);
}

}

  • Forum posts: 7

Apr 21, 2014 5:48:29 PM via Website

<ListView
    android1:id="@+id/listView1"
    android1:layout_width="wrap_content"
    android1:layout_height="wrap_content"
    android1:layout_alignParentLeft="true"
    android1:layout_alignParentTop="true" >
</ListView>
<GridView 
    android:id="@+id/grid_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnWidth="150dp"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="40dp"
    android:numColumns="3"
    android:gravity="center"
    android:stretchMode="columnWidth" > 


<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="Small Text"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textStyle="bold" />

  • Forum posts: 7

Apr 21, 2014 5:51:19 PM via Website

Hi,

i have a Listview...click on Listitem open image and text after open full image...pls help full code..

i have a error message :Activity Not Found Exception...Pls sharing the code This i s i wright code... MainActivity.java

package com.example.prj_10;

import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity { ListView list; String[] kkTitles; String[] kkDescriptions; int[] images={R.drawable.anamrama1,R.drawable.aruna2,R.drawable.mukesh3,R.drawable.nagendra4,R.drawable.balaraju5};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Resources res=getResources();
    kkTitles=res.getStringArray(R.array.titles);
    kkDescriptions=res.getStringArray(R.array.descriptions);

    list=(ListView) findViewById(R.id.listView1);
    MainAdapter adapter=new MainAdapter(this,kkTitles,images,kkDescriptions);
    list.setAdapter(adapter);


    GridView gridView = (GridView) findViewById(R.id.grid_view);

    // Instance of ImageAdapter Class
    gridView.setAdapter(new ImageAdapter(this));

    /**
     * On Click event for Single Gridview Item
     * */
    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), FullImage.class);
            // passing array index
            i.putExtra("id", position);
            startActivity(i);
        }
    });
}
class MainAdapter extends ArrayAdapter<String>
{
    Context context;
    int[] images;
    String[] titleArray;
    String[] descriptionArray;
    private ImageView myImage1;
    MainAdapter(Context c,String[] titles,int imgs[],String[] desc)
    {
        super(c,R.layout.activity_main,R.id.textView1,titles);
        this.context=c;
        this.images=imgs;
        this.titleArray=titles;
        this.descriptionArray=desc;

    }
    @Override
     public View getView(int position,View convertView,ViewGroup parent){
        LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.activity_main,parent,false);
        ImageView myImage1=(ImageView) row.findViewById(R.id.imageView1);
        TextView myTitle=(TextView) row.findViewById(R.id.textView1);
        TextView myDescription=(TextView) row.findViewById(R.id.textView2);
        myImage1.setImageResource(images[position]);
        myTitle.setText(titleArray[position]);
        myDescription.setText(descriptionArray[position]);

        return row;
    }

} }

ImageAdapter.java

package com.example.prj_10;

import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter { private Context mContext;

// Keep all Images in array
public Integer[] mThumbIds = {
        R.drawable.anamrama1,

};

// Constructor
public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
    return imageView;
}

}

FullImage.java

package com.example.prj_10;

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView;

public class FullImage extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    int position = i.getExtras().getInt("id");
    ImageAdapter imageAdapter = new ImageAdapter(this);

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view1);
    imageView.setImageResource(imageAdapter.mThumbIds[position]);
}

}

activity_main.xml

<ListView
    android1:id="@+id/listView1"
    android1:layout_width="wrap_content"
    android1:layout_height="wrap_content"
    android1:layout_alignParentLeft="true"
    android1:layout_alignParentTop="true" >
</ListView>
<GridView 
    android:id="@+id/grid_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnWidth="150dp"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="40dp"
    android:numColumns="3"
    android:gravity="center"
    android:stretchMode="columnWidth" > 


<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="Small Text"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textStyle="bold" />