0% found this document useful (0 votes)
2 views12 pages

Dam Lab9

Uploaded by

AdrCtV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Dam Lab9

Uploaded by

AdrCtV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1. Verificati aplicatia 1 si 2.

Aplicatie pentru afisarea imaginilor in format galerie foto. Click pe o imagine => pozitia sa in galerie.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="110dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" />

ImageAdapter.java

package com.example.damlaborator9ex1;
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;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return ImagineMica.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// crearea unui nou ImageView pentru fiecare item la care face
referire Adaptorul
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(200,
200));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(ImagineMica[position]);
return imageView;
}
// adaugarea imaginilor in arraylist
public Integer[] ImagineMica = {
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5
};
}

MainActivity.java

package com.example.damlaborator9ex1;
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;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return ImagineMica.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// crearea unui nou ImageView pentru fiecare item la care face
referire Adaptorul
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(200,
200));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(ImagineMica[position]);
return imageView;
}
// adaugarea imaginilor in arraylist
public Integer[] ImagineMica = {
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5
};
}
Aplicatie pentru afisarea imaginilor in format galerie foto. Click pe o imagine => imaginea marita
separat.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="110dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" />

image_details.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/full_image_view"
android:layout_width="match_parent"
android:layout_height="570dp"
android:layout_margin="10dp" />
</LinearLayout>

ImageAdapter.java

package com.example.damlaborator9ex1;
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;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return ImagineMica.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// crearea unui nou ImageView pentru fiecare item la care face
referire Adaptorul
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(200,
200));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(ImagineMica[position]);
return imageView;
}
// adaugarea imaginilor in arraylist
public Integer[] ImagineMica = {
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5
};
}

FullImageActivity.java

package com.example.damlaborator9ex1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class FullImageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_details);
// Get intent data
Intent i = getIntent();
// Get Selected Image Id
int position = i.getExtras().getInt("id");
com.example.damlaborator9ex1.ImageAdapter imageAdapter =
new
com.example.damlaborator9ex1.ImageAdapter(this);
ImageView imageView = (ImageView)
findViewById(R.id.full_image_view);

imageView.setImageResource(imageAdapter.ImagineMica[position]);
}
}

MainActivity.java

package com.example.damlaborator9ex1;
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;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return ImagineMica.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// crearea unui nou ImageView pentru fiecare item la care face
referire Adaptorul
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(200,
200));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(ImagineMica[position]);
return imageView;
}
// adaugarea imaginilor in arraylist
public Integer[] ImagineMica = {
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5
};
}
2. Creati o galerie foto cu 10 imagini de masini. La fiecare masina se va afisa informatii despre ea si
imaginea marita.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="110dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="@color/white"/>

image_details.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/full_image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />

<TextView
android:id="@+id/textImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="sans-serif-light"
android:textSize="20sp" />

<TextView
android:id="@+id/textImage2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="sans-serif-light"
android:textSize="20sp" />
<Button
android:id="@+id/butonInapoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:text="Inapoi"/>

</LinearLayout>

FullImageActivity.java

package com.example.damlaborator9ex1;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class FullImageActivity extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_details);
// Get intent data
Intent i = getIntent();
String Info1[] = new String[]{
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz",
"Mercedes-Benz"
};
String Info2[] = new String[]{
"G Class",
"S Class",
"A Class",
"C Class",
"E Class",
"GLC",
"CLS",
"GLE",
"B Class",
"AMG"
};
// Get Selected Image Id
Button inapoi;
inapoi = findViewById(R.id.butonInapoi);
int position = i.getExtras().getInt("id");
com.example.damlaborator9ex1.ImageAdapter imageAdapter =
new
com.example.damlaborator9ex1.ImageAdapter(this);
ImageView imageView = (ImageView)
findViewById(R.id.full_image_view);
TextView textView = (TextView)
findViewById(R.id.textImage);
textView.setText(Info1[position]);
@SuppressLint({"MissingInflatedId", "LocalSuppress"})
TextView textView1 = (TextView) findViewById(R.id.textImage2);
textView1.setText(Info2[position]);

imageView.setImageResource(imageAdapter.ImagineMica[position]);
inapoi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}

ImageAdapter.java

package com.example.damlaborator9ex1;
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;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return ImagineMica.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// crearea unui nou ImageView pentru fiecare item la care face
referire Adaptorul
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(400,
250));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(ImagineMica[position]);
return imageView;
}
// adaugarea imaginilor in arraylist
public Integer[] ImagineMica = {
R.drawable.p1, R.drawable.p2,
R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6,
R.drawable.p7, R.drawable.p8,
R.drawable.p9, R.drawable.p10
};
}

MainActivity.java

package com.example.damlaborator9ex1;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gv = (GridView) findViewById(R.id.gridview);
gv.setAdapter(new
com.example.damlaborator9ex1.ImageAdapter(this));
gv.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id)
{
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(),

com.example.damlaborator9ex1.FullImageActivity.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
}

You might also like