i really need your help to solve a problem that might appear stupid for a lot of you.
I need to create a simple Grindview and fill it with images. I tried the sample code provided by the android developers site and it works nicely.
The problem is that the sample code provides images from drawable. I need to fill it with bitmaps that are stored in my sqlite Db as BLOB.
The db is tested and working, and i'm able to obtain the bitmap from the BLOB without problem.
In my code, when the activity starts, nothing happens and i get a white screen without images. I spent many hours on this, i hope that you can give me some tips!!! Thank you in advance for the replies!!! :D
This is my class code:
package cover.me;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import cover.me.Game.SimulationView.Cursor;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class Gallery extends Activity{
private LinearLayout myGallery;
private android.database.Cursor cursor;
private DbAdapter MyDb;
private int x,y;
private Display display;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter{
private Context mContext;
private DbAdapter MyDb;
private int Counter;
private ArrayList<Bitmap> Images = new ArrayList<Bitmap>();
private boolean ImagesLoaded = false;
public ImageAdapter(Context c){
mContext = c;
}
public int getCount() {
return 0;
}
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){
if(ImagesLoaded == false){ //Add bitmap to Images ArrayList the first time that getView is called
MyDb = new DbAdapter(Gallery.this);
MyDb.open();
cursor = MyDb.fetchAllLevels();
cursor.moveToFirst();
for(int i=0;i<cursor.getCount()-1;i++){
byte[] image = cursor.getBlob(cursor.getColumnIndex(DbAdapter.LvL_Bitmap));
ByteArrayInputStream inputStream = new ByteArrayInputStream(image);
Bitmap mBitmap = BitmapFactory.decodeStream(inputStream);
Images.add(mBitmap);
cursor.moveToNext();
}
cursor.close();
MyDb.close();
ImagesLoaded = true;
}
ImageView imageView;
if (convertView == null){
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.setImageBitmap(Images.get(Counter));
Counter++;
return imageView;
}
}
}
And here the 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="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"
/>
This is my first question here on StackOverflow, so give me some tips if i did something wrong with my question!!! Thank you!
This is an old question but it hasn't been answered yet. I believe your problem is that you are returning 0 in your getCount method. I was working on a previous project that is very similar to this one and found this error in mine. getCount needs to return the total number of entries you are wanting to view.
public int getCount() {
return 0; //Needs to return something other than zero
}
Related
I'm testing a simple grid adapter with a custom object, the app runs on the device without a problem but stays blank instead of inflating the activity with the specified grid items. This is my code.
Main Activity
package com.example.nobodyme.errorrepository;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import java.util.ArrayList;
public class MainActivity extends ActionBarActivity {
GridView gridView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<GridItems> gridItems = new ArrayList<>();
gridItems.add(new GridItems("Android", 2));
gridItems.add(new GridItems("Java", 3));
gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new GridViewAdapter(this, gridItems));
}
}
GridViewAdapter
package com.example.nobodyme.errorrepository;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
public class GridViewAdapter extends ArrayAdapter<GridItems> {
private Context context;
int b;
public GridViewAdapter(Context context, List<GridItems> gridItems) {
super(context, 0, gridItems);
b=gridItems.size();
}
public View getView(int position, View convertView, ViewGroup parent) {
View gridView = convertView;
if(gridView == null)
{
gridView = LayoutInflater.from(getContext()).inflate(
R.layout.grid_view, parent, false);
}
GridItems currentgriditem = getItem(position);
TextView mMaintextView = (TextView) gridView.findViewById(R.id.grid_item_main);
mMaintextView.setText(currentgriditem.getTitle());
TextView mUnansweredtextView = (TextView) gridView.findViewById(R.id.grid_item_unanswered);
mUnansweredtextView.setText(currentgriditem.getUnansweredNo());
return gridView;
}
#Override
public int getCount() {
return b;
}
#Override
public long getItemId(int position) {
return 0;
}
}
GridItems
package com.example.nobodyme.errorrepository;
/**
* Created by nobodyme on 15/1/17.
*/
public class GridItems {
/** Grid title*/
private String mTitle;
/** NO of unanswered items in the gird **/
private Integer mUnansweredNo;
public GridItems(String Title, Integer UnansweredNo) {
mTitle = Title;
mUnansweredNo = UnansweredNo;
}
public String getTitle() {
return mTitle;
}
public Integer getUnansweredNo() {
return mUnansweredNo;
}
}
I have edited the code as per the comments and the app still crashes.
You're overriding getCount and returning zero in the adapter. Don't override this, or return the correct number of items.
Please check below code :
#Override
public int getCount() {
return gridItems.size();
}
Instead of 0 returning, You should return your list size.
You need define gridItems List on your arrayAdapter and set it on the constructor
and override getCount to return the gridItems (adapterGridItems) size
private List<GridItems> adapterGridItems;
public GridViewAdapter(Context context, List<GridItems> gridItems) {
super(context, 0, gridItems);
//set adapterGridItems
this.adapterGridItems=gridItems;
}
#Override
public int getCount() {
return adapterGridItems.size();
}
please, check
mMaintextView.setText(currentgriditem.getUnansweredNo());
you are passing a integer so mMainTextView.setText will find a resource with currentgriditem.getUnansweredNo() id, i think you are trying to set currentgriditem.getUnansweredNo() as string, so this will work
mMaintextView.setText(currentgriditem.getUnansweredNo()+"");
are you sure that is mMaintextView.setText(currentgriditem.getUnansweredNo()+"");
and not
mUnansweredtextView.setText(currentgriditem.getUnansweredNo()+"");
?
In order to tell the adapter how many GridItems to show we need to override the getCount method as shown above by #samsad.
The reason the compiler complains that it can't recognize symbol griditems is because you haven't created a field to store a reference to the GridItems in your adapter.
Try creating a field for the ArrayList of GridItems in your adapter to fix the issue.
I have prepared a grid view in a fragment which shows images and when you click on them it shows the image in another Activity. I want the name of the image to be shown below it for that i took a textview but it shows position. How to show the name of the photo choosen from grid view on that textview. Below is the code fragments.
full_image_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:id="#+id/full_image_view"
android:layout_width="500dp"
android:layout_height="500dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/image_title"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
FullImageFragment
package com.androidbelieve.HIT_APP;
import android.app.Activity;
/**
* Created by Akash on 2/13/2016.
*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class FullImageFragment extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image_layout);
// 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_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
TextView textView = (TextView) findViewById(R.id.image_title);
textView.setText(String.valueOf(position));
}
}
GalleryFragment
package com.androidbelieve.HIT_APP;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
/**
* Created by Ratan on 7/29/2015.
*/
public class GalleryFragment extends Fragment {
private GridView gridView;
private ImageView imageView;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_gallery_grid, container,
false);
GridView gridView = (GridView) view.findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(view.getContext()));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(),FullImageFragment.class);
i.putExtra("id",position);
startActivity(i);
}
});
return view;
}
}
Please Help Me Out!!!
ImageAdapter
package com.androidbelieve.HIT_APP;
/**
* Created by Akash on 2/13/2016.
*/
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import java.util.ArrayList;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.akash, R.drawable.akash,
R.drawable.akash , R.drawable.akash,
};
// 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(200, 200));
return imageView;
}
}
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(),FullImageFragment.class);
i.putExtra("id",position);
i.putExtra("image_name",arrayImageName[position]); // get your selected image name and pass it
startActivity(i);
}
});
In your image display class,
String name = i.getExtras().getString("image_name");
TextView textView = (TextView) findViewById(R.id.image_title);
textView.setText(name);
You can do this way:
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.akash, R.drawable.akash,
R.drawable.akash , R.drawable.akash,
};
public String[] mThumbNames = {
"akash 0", "akash 1","akash 2", "akash 3",
};
In Next Activity:
TextView textView = (TextView) findViewById(R.id.image_title);
textView.setText(imageAdapter.mThumbNames[position])
Edit 1:
private class CustomClass{
public int drawable;
public String title;
public String information;
}
ArrayList<CustomClass> listCustom = new ArrayList<>();
Integer[] mThumbIds = {
R.drawable.akash, R.drawable.akash,
R.drawable.akash , R.drawable.akash,
};
String[] mThumbNames = {
"akash 0", "akash 1","akash 2", "akash 3",
};
String[] mThumbInfos = {
"akash 0 Info", "akash 1 Info","akash 2 Info", "akash 3 Info",
};
for (int i = 0; i < mThumbIds.length; i++) {
CustomClass customClass = new CustomClass();
customClass.drawable = mThumbIds[i];
customClass.title = mThumbNames[i];
customClass.information = mThumbInfos[i];
listCustom.add(customClass);
}
Hope this will help you.
I think you want something like this?
Hiren Patel has already answered that. I am just putting it in steps.
1) create 'CustomClass' which will act as POJO class to structure your image name, resource reference.
2) Create an adapter with extends ArrayAdapter and take 'CustomClass' as argument
3) In your activity, create a list of that class and load the data (Image name, resource id etc)
4)Initialize your adapter with above list (can be array as well)
5) access that values on getView method of adapter
I was wondering if it is possible to apply two different Adapters (ArrayAdapter for a String array, and ImageAdapter for the background of each value in the array) for a certain 4X4 dimension grid… I ask this because my actual (the code below is just a sample) program contains user-inputted values for height and width (https://stackoverflow.com/questions/35382979/android-auto-fitting-row-height-of-gridview-based-on-user-inputted-values) as opposed to hardcoding. Say, if I wanted to assign the brown blocks as a background for the odd numbers, and the gray blocks for the even numbers using grid.setAdapter() for both Adapters... How would I code that using Android Studio?
Here's the following Java code for the grid:
package dpark.sample;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private int height, width;
String[] list;
GridView grid;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
height = 4;
width = 4;
buildList();
grid = (GridView)findViewById(R.id.gridView);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, list);
grid.setAdapter(adapter);
grid.setNumColumns(width);
//***TEMPORARILY COMMENTING THE FOLLOWING OUT SINCE THIS WILL JUST OVERWRITE THE
// ARRAYADAPTER***
//grid.setAdapter(new ImageAdapter(getApplicationContext()));
}
private void buildList() {
int tempIncrementor = 1;
int dimensions = height * width;
list = new String[dimensions];
for (int i = 0; i < dimensions; i++) {
list[i] = String.valueOf(tempIncrementor);
tempIncrementor++;
}
}
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.brownblock,
R.drawable.grayblock
};
}
}
... Which outputs in the virtual emulator:
... As for outputting the color block images, I temporarily commented out the ArrayAdapter blocks in my code so I could output the following:
No you can't set two adapters beacuse the method setAdapter overrides the previous one.
But your goal doesn't require it, you should store the values in arraylist and retrieve them in the getView method.
Although there are many tutorials out there, I've found it really difficult to implement an AsyncTask to load images from URI's (obtained from a content provider) into a custom adapter.
I get the basic gist, which is to have a class containing an AsyncTask, do the bitmap creation in the 'doInBackground', and then set the ImageView in the onPostExecute.
The problem for me, being new to android & programming, is that I don't know how to pass in my Uri's to the AsyncTask for each item, how to create the bitmap, and how to return it to the adapter.
I've only gotten this far with the actual AsyncTask class (ImageLoader):
package another.music.player;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.widget.ImageView;
public class ImageLoader extends AsyncTask<String, String, Bitmap> {
private ImageView imageView;
private Bitmap bitmap = null;
#Override
protected Bitmap doInBackground(String... uri) {
// Create bitmap from passed in Uri here
return bitmap;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null && imageView != null) {
imageView.setImageBitmap(bitmap);
}
}
}
And my custom adapter looks like this:
package another.music.player;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.provider.MediaStore.Audio.AlbumColumns;
import android.provider.MediaStore.Audio.AudioColumns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;
class AlbumAdapter extends CursorAdapter {
public AlbumAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
}
private static Uri currentSongUri;
#Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView albumArt = (ImageView) view.getTag(R.id.albumArt);
TextView text1 = (TextView) view.getTag(R.id.artistTitle);
TextView text2 = (TextView) view.getTag(R.id.albumTitle);
TextView text3 = (TextView) view.getTag(R.id.totalSongs);
albumArt.setImageBitmap(null);
text1.setText(cursor.getString(cursor
.getColumnIndex(AudioColumns.ARTIST)));
text2.setText(cursor.getString(cursor
.getColumnIndex(AudioColumns.ALBUM)));
text3.setText(cursor.getString(cursor
.getColumnIndex(AlbumColumns.NUMBER_OF_SONGS)));
String currentAlbumId = cursor.getString(cursor
.getColumnIndex(BaseColumns._ID));
Integer currentAlbumIdLong = Integer.parseInt(currentAlbumId);
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
currentSongUri = ContentUris.withAppendedId(artworkUri,
currentAlbumIdLong);
//Run ImageLoader AsyncTask here, and somehow retrieve the ImageView & set it.
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.albumitem, null);
view.setTag(R.id.albumArt, view.findViewById(R.id.albumArt));
view.setTag(R.id.artistTitle, view.findViewById(R.id.artistTitle));
view.setTag(R.id.albumTitle, view.findViewById(R.id.albumTitle));
view.setTag(R.id.totalSongs, view.findViewById(R.id.totalSongs));
return view;
}
}
I would be very grateful if somebody could show me how to proceed with this.
Thanks.
You need to pass your AsyncTask the view so that it can update it when it completes:
//Run ImageLoader AsyncTask here, and let it set the ImageView when it is done.
new ImageLoader().execute(view, uri);
And modify AsyncTask so that it can handle mixed parameter types:
public class ImageLoader extends AsyncTask<Object, String, Bitmap> {
private View view;
private Bitmap bitmap = null;
#Override
protected Bitmap doInBackground(Object... parameters) {
// Get the passed arguments here
view = (View) parameters[0];
String uri = (String)parameters[1];
// Create bitmap from passed in Uri here
// ...
return bitmap;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null && view != null) {
ImageView albumArt = (ImageView) view.getTag(R.id.albumArt);
albumArt.setImageBitmap(bitmap);
}
}
}
I haven't tested this code but it should give you an idea.
Why are you doing setImage in AsyncTask? You can do it in a thread. I don't think in this condition AsyncTask would be good. Better you do it in different thread.
I am trying to display pictures that I had placed in the drawable folder using a Gridview. I am getting some errors. My code and the errors I am getting are shown below.
package com.newapp;
import android.R;
import android.R.drawable;
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;/*Error here: main cannot be resolved or is not a field*/
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);/*Error here: main cannot be resolved or is not a field*/
GridView gridview = (GridView) findViewById(R.id.photogrid);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(MainActivity.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.sample_0, /*Error here: sample_0 cannot be resolved and is not a field*/
R.drawable.sample_1,/*Error here: sample_1 cannot be resolved and is not a field*/
R.drawable.sample_2,/*Error here: sample_2 cannot be resolved and is not a field*/
R.drawable.sample_3,/*Error here: sample_3 cannot be resolved and is not a field*/
R.drawable.sample_4,/*Error here: sample_4 cannot be resolved and is not a field*/
R.drawable.sample_5/*Error here: sample_5 cannot be resolved and is not a field*/,
R.drawable.sample_6,
/*Error here: sample_6 cannot be resolved and is not a field*/
};
}
So can somebody tell me what is causing these problems? Any help will be much appreciated.
Thanks in advance
Here is your first problem: import android.R
Do not import this as this is the android system's R package, and not your own project's R file, hence main cannot be identified, as the R you are referring to for main in the android.R package does not exist.
If you remove this import, "main" will be recognized, as your own R file will be referenced. The same rule applies for the ImageAdapter. If your remove the import: import android.R.drawable you will avoid the problems you have in this class.