Pro11Activity.java
package ps.pro11;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class Pro11Activity extends Activity implements OnItemClickListener {
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv=(ListView) findViewById(R.id.listView1);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(this, pos + " click", Toast.LENGTH_SHORT).show();
Intent myintent=new Intent(this,Details.class);
myintent.putExtra("id", pos);
startActivity(myintent);
}
}
ImageAdapter.java
package ps.pro11;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
Context c;
int id;
Integer listmarutisuzuki[]={R.drawable.marutisuzuki1,R.drawable.marutisuzuki2,R.drawable.marutisuzuki3};
Integer listalto[]={R.drawable.alto1,R.drawable.alto2,R.drawable.alto3};
Integer listhundai[]={R.drawable.hundai1,R.drawable.hundai2,R.drawable.hundai3};
Integer listoodi[]={R.drawable.oodi1,R.drawable.oodi2,R.drawable.oodi3};
public ImageAdapter(Context c,int id)
{
this.c=c;
this.id=id;
Log.d("master", id+"clicked");
}
@Override
public int getCount() {
// TODO Auto-generated method stub
if(id==0)
{
return listmarutisuzuki.length;
}
if(id==1)
{
return listalto.length;
}
if(id==2)
{
return listhundai.length;
}
if(id==3)
{
return listoodi.length;
}
return listmarutisuzuki.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView img=new ImageView(c);
if(id==0)
{
img.setImageResource(listmarutisuzuki[arg0]);
}
if(id==1)
{
img.setImageResource(listalto[arg0]);
}
if(id==2)
{
img.setImageResource(listhundai[arg0]);
}
if(id==3)
{
img.setImageResource(listoodi[arg0]);
}
img.setScaleType(ImageView.ScaleType.FIT_XY);
img.setLayoutParams(new Gallery.LayoutParams(120, 200));
return img;
}
}
Details.java
package ps.pro11;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.TextView;
import android.widget.Toast;
public class Details extends Activity implements OnItemClickListener {
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
TextView tvname,tvdate,tvcompanyname;
Gallery gv;
ImageAdapter obj;
int id=0;
Integer listmarutisuzuki[]={R.drawable.marutisuzuki1,R.drawable.marutisuzuki2,R.drawable.marutisuzuki3};
Integer listalto[]={R.drawable.alto1,R.drawable.alto2,R.drawable.alto3};
Integer listhundai[]={R.drawable.hundai1,R.drawable.hundai2,R.drawable.hundai3};
Integer listoodi[]={R.drawable.oodi1,R.drawable.oodi2,R.drawable.oodi3};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
tvname=(TextView) findViewById(R.id.textViewname);
tvdate=(TextView) findViewById(R.id.textViewdate);
tvcompanyname=(TextView) findViewById(R.id.textViewcompanyname);
gv=(Gallery) findViewById(R.id.gallery1);
Intent myintent=getIntent();
id=myintent.getIntExtra("id", 0);
if(id==0)
{
tvname.setText("maruti suzuki");
tvdate.setText("1-12-1987");
tvcompanyname.setText("Maruti");
}
if(id==1)
{
Toast.makeText(this, id+" clicked", Toast.LENGTH_SHORT).show();
tvname.setText("maruti alto");
tvdate.setText("2-01-1988");
tvcompanyname.setText("Maruti");
}
if(id==2)
{
tvname.setText("hundai i10");
tvdate.setText("2-12-1987");
tvcompanyname.setText("Hundai");
}
if(id==3)
{
tvname.setText("oodi");
tvdate.setText("1-10-1993");
tvcompanyname.setText("Oodi");
}
obj=new ImageAdapter(this,id);
gv.setAdapter(obj);
gv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3)
{
// TODO Auto-generated method stub
Intent myintent2=new Intent(this,enlarge.class);
if(id==0)
myintent2.putExtra("id", listmarutisuzuki[pos]);
else if(id==1)
myintent2.putExtra("id", listalto[pos]);
else if(id==2)
myintent2.putExtra("id", listhundai[pos]);
else if(id==3)
myintent2.putExtra("id", listoodi[pos]);
//myintent2.putExtra("id", arg0.getId());
startActivity(myintent2);
//Toast.makeText(this," selected", Toast.LENGTH_SHORT).show();
}
}
enlarge.java
package ps.pro11;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class enlarge extends Activity
{
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.enlarge);
Intent myintent2=getIntent();
int id=myintent2.getIntExtra("id", 0);
imgview=(ImageView) findViewById(R.id.imageView1);
imgview.setImageResource(id);
}
}
No comments:
Post a Comment