Place single image in multiple places without creating imageview - android

hi guys i need to place a single image in multiple places.
suppose i need to place one image in 5 places in a layout but using only one <ImageView> id
<ImageView
android:id="#+id/img"
android:layout_width="340dip"
android:layout_height="240dip"
android:layout_marginBottom="60dip" />
how to acheive this please help.

Use This code for which uses Grid View :
Main.java:
package sra.gri.vie;
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 Main 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(Main.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.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon,
};
}
}
main.xml: // the layout
<?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"
/>
Lat me know if this post is of any help :)

you can do like this
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);
ImageView iv = new ImageView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50; params.topMargin = 60;
rl.addView(iv, params);
and then add this r1 in your main view then again change margin, height and other param and add again like this you do n no of times

Do you try include tag for it?
img.xml
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_home"/>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="#layout/img"/>
<include layout="#layout/img"/>
<include layout="#layout/img"/>
<include layout="#layout/img"/>
</LinearLayout

Related

ImageButton inside of GridView not clickable

Here is my code for dynamically creating ImageButtons inside of gridviews. When I run the activity, the ImageButtons are not clickable. I tried adding
android:descendantFocusability="blocksDescendants"
to the xml file but this did not fix the problem.
EDIT: I updated the adapter to be for ImageViews, not ImageButtons, but the problem persists.
Here is my custom adapter:
package com.example.myname.myproject;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
/**
* Created by myname on 3/31/17.
*/
public class ImageArrayAdapter extends BaseAdapter {
Context context;
int[] currentResources;
String[] currentIcons;
public ImageArrayAdapter(Context context, String[] currentIcons, int[] currentResources){
ImageArrayAdapter.this.context = context;
ImageArrayAdapter.this.currentIcons = currentIcons;
ImageArrayAdapter.this.currentResources = currentResources;
}
#Override
public int getCount() {
return currentResources.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
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(context);
imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setBackgroundColor(Color.TRANSPARENT);
} else {
imageView = (ImageView) convertView;
}
imageView.setClickable(true);
imageView.setImageResource(currentResources[position]);
return imageView;
}
}
Here is my xml file for the GridView.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.myname.myproject.AdminControlTabbed$PlaceholderFragment">
<GridView
android:id="#+id/templateGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
/>
Thanks for the help.
Why not ImageViews instead of ImageButtons. Then you have to only set an OnItemClickListener for your GridView in the activity class where you have initialized it. After you attach the adapter to it, you can attach a clickListener too like this:
myGridView.setAdapter(this, currentIconsArray, currentResourcesArray);
myGridViewsetOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//code for handling onClick event
}
});
Activity.dispatchTouchEvent(MotionEvent) dispach it to other listeners

android - try to add setonitemclicklistener to gridview and get a mistake

I am new to Android and I'm trying to add setOnItemClickListener to my gridview and i am getting the following error:
setOnItemClickListener in AdapterView cannot by applied to MainActivity
for this code line: grid.setOnItemClickListener(this);
What am I doing wrong? Could you help me please?
Here is my code
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v7.app.AppCompatActivity;
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.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
GridView grid;
TextView tvTest;
TextView tvTest2;
Random rnd = new Random();
int color;
ImageView imageView;
ArrayList<Integer> colorInts = new ArrayList<Integer>();
ArrayList<Integer> itemsList = new ArrayList<Integer>();
Integer[] items;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
grid = (GridView) findViewById(R.id.grid);
tvTest =(TextView) findViewById(R.id.tvTest);
tvTest2 =(TextView) findViewById(R.id.tvTest2);
adjustGridView();
itemsList.add(R.drawable.lemon);
itemsList.add(R.drawable.lemon);
itemsList.add(R.drawable.lemon);
itemsList.add(R.drawable.lemon);
itemsList.add(R.drawable.lemon);
itemsList.add(R.drawable.lemon);
// ArrayList into Array
items = new Integer[ itemsList.size() ];
itemsList.toArray( items );
grid.setAdapter(new CustomGridAdapter(this, items));
grid.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Clicked postion is " + arg2,
Toast.LENGTH_SHORT).show();
tvTest.setText("Number of color: "+ colorInts);
tvTest2.setText("Number of color: "+ colorInts.get(arg2));
}
// Here is your custom Adapter
public class CustomGridAdapter extends BaseAdapter {
private AppCompatActivity mContext;
// Keep all Images in array
public Integer[] mThumbIds;
// Constructor
public CustomGridAdapter(MainActivity mainActivity, Integer[] items) {
this.mContext = mainActivity;
this.mThumbIds = items;
}
#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 = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
imageView.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
colorInts.add(color);
return imageView;
}
}
private void adjustGridView() {
grid.setNumColumns(3); //(GridView.AUTO_FIT);
grid.setColumnWidth(80);
grid.setVerticalSpacing(5);
grid.setHorizontalSpacing(5);
grid.setStretchMode(GridView.NO_STRETCH);
}
}
and here is the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.testrk.basiclayout001.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/myColor02"
android:layout_weight="2"
>
<TextView
android:id="#+id/tvTest"
android:background="#color/myColor04"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/myColor01"
android:focusable="false"
android:layout_weight="1"
>
<GridView
android:id="#+id/grid"
android:focusable="true"
android:clickable="true"
android:background="#color/myColor03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
</GridView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/myColor02"
android:layout_weight="2"
>
<TextView
android:id="#+id/tvTest2"
android:background="#color/myColor04"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
and cell.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ImageView>
The setOnItemClickListener method does not take in the context as an argument, it takes in an OnItemClickListener object. What you need to do is pass in a new OnItemClickListener in the method call and then override the OnItemClick method.
Example:
grid.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> adapter, View v, int position,
long arg3)
{
//code to be executed on click
}
I hope this answers your question.

GridView is not shown in an example with Navigation Drawer

I've downloaded the Navigation Drawer example from the developers guide, I try to implement a GridView into an Activity of one of the options of the Drawer, but in execution time the GridView doesn't appears, the IDE doesn't show me any errors and in an example apart I can do it de GridView successfuly, How do I correct this problem?
My code is here:
In the MainActivity I use the same like the example with
Fragment fragment;
FragmentManager fragmentManager;
fragment = new inicioFragment(R.layout.inicio);
fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
InicioActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
public class InicioActivity extends Activity {
TextView tv1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inicio);
tv1=(TextView)findViewById(R.id.tv1);
GridView gv = (GridView)findViewById(R.id.gridView1);
gv.setAdapter(new ImageAdapter(this.getApplicationContext()));
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
String g=Integer.toString(position);
tv1.setText(g);
}
});
}
}
ImageAdapter.java
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 mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
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(13, 13, 13, 13);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Integer[] mThumbIds = {
R.drawable.image_2, R.drawable.image_3,
R.drawable.image_4, R.drawable.image_5,
R.drawable.image_6, R.drawable.image_7,
R.drawable.image_0, R.drawable.image_1,
R.drawable.image_2, R.drawable.image_3,
R.drawable.image_4, R.drawable.image_5,
R.drawable.image_6, R.drawable.image_7,
R.drawable.image_0, R.drawable.image_1,
R.drawable.image_2, R.drawable.image_3,
R.drawable.image_4, R.drawable.image_5,
R.drawable.image_6, R.drawable.image_7
};
}
inicio.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="230dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearLayout1"
android:orientation="vertical" >
<TextView
android:id="#+id/tv2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Aqui van las notificaciones push de facebook" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="230dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<GridView
android:id="#+id/gridView1"
android:layout_width="156dp"
android:layout_height="192dp"
android:numColumns="2" >
</GridView>
<TextView
android:id="#+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical"
android:text="InformaciĆ³n" />
</LinearLayout>
</RelativeLayout>
Thanks for your collaboration!!
Try to change InicioActivity into a fragment.
And check this question. I think you are facing the same problem.
The following worked for me. In Android Studio:
1) Create a new Navigation Drawer Activity from the list of activity templates.
2) Note that several layout files will be created for you, including a content_main.xml. Replace the XML in the content_main.xml file with your <GridView> XML.
3) Create the relevant XML files or Java classes for the GridView, eg. the ImageAdapter class and an XML file for the GridView item layout.

Android:Grid View

I want to ask how can i resize the size of the grid to a larger size according to my needs.
here is my xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<GridView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/grid_view"
android:columnWidth="150dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:padding="20dp"
android:gravity="center" />
</RelativeLayout>
here is my layout file:
package com.example.steve_jobs;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.grid_view);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
image adapter class:
package com.example.steve_jobs;
import android.content.Context;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.view.ViewGroup;
/**
* Created by yash on 19/6/13.
*/
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.sj_1,
R.drawable.sj_2,
R.drawable.sj_3,
R.drawable.sj_4,
R.drawable.sj_5,
R.drawable.sj_6,
R.drawable.sj_7,
R.drawable.nexus
};
}
You could remove or reduce all that padding!
edit:
try
android:stretchColumns="0,1,2"
0, 1 and 2 represent indexes of your columns;
so if you have 6 columns you would use "0,1,2,3,4,5"
you should use this
<GridView
android:id="#+id/myGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

gridview in custom dialog not working...?

I have tried adding a grid view to a custom dialog. When displaying
the dialog it crashes.
But when tried displaying the grid view in normal activity it was
working.( without dialog )
I took the examples from developer android website.Took grid view and
tried to integrate in custom dialog.
I used two xml main.xml & category.xml.
Here is my code:
package com.android.test;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
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.widget.AdapterView.OnItemClickListener;
public class test extends Activity {
/** Called when the activity is first created. */
public final static int CATEGORY_ID=0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.categories);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
showDialog(CATEGORY_ID);
}
});
}
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch(id) {
case CATEGORY_ID:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = this;
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.categorydialog,
(ViewGroup)
findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView)
layout.findViewById(R.id.image);
image.setImageResource(R.drawable.find);
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(test.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
dialog = builder.create();
break;
default:
dialog = null;
}
return dialog;
}
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.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find,
R.drawable.info, R.drawable.find
};
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dip"
android:orientation="vertical">
<Button android:id="#+id/categories"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Choose categories"
/>
</LinearLayout>
categorydialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:id="#+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
<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"
/>
</LinearLayout>
Could anyone please help me out here.
Change this line:
GridView gridview = (GridView) findViewById(R.id.gridview);
to something like this:
GridView gridview = (GridView) layout.findViewById(R.id.gridview);

Categories

Resources