Android Developers: HelloGallery tutorial: "android.R.styleable cannot be resolved" - G1 Android Development

Android Developers: HelloGallery tutorial: "android.R.styleable cannot be resolved"
Hello,
I've been following the Views tutorials included in the android developer site:
http://developer.android.com/guide/t...o-gallery.html
When testing the "Hello Gallery" view, I get the compile-time error:
"android.R.styleable cannot be resolved"
I searched for this error on this group but is wasn't answered.
Can anyone help?
The problem reference occurs in the imageAdapter class that is appended after the onCreate() method in the HelloGallery class:
public class ImageAdapter extends BaseAdapter
{
...
TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
}
Strangely enough, when I insert this line into the onCreate() method at the start of the package, there is no problem. It seems that the android.R class is not known to this class.
Thanks,
Paul

any resolution to this issue?
I am running into the same issue and was wondring if you had found a resolution?
Thanks in advance,
-Nathan

tell me you know what is import

If it is what you mean, "import android.R.styleable" is not possible.

vincebodi said:
If it is what you mean, "import android.R.styleable" is not possible.
Click to expand...
Click to collapse
No, it's impossible. As I realized after I did that post, they changed the example codes in 1.5 SDK and broke some applications. If you lose "android." the code should compile.

I copied "ImageAdapter" Class into "HelloGallery" Class. And it's work.
Here is my code:
package com.example.hellogallery;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class HelloGallery extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
Toast.makeText(HelloGallery.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7 };
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}

attrs.xml and obtainStyledAttributes
Thanks for the code tonghoho...I still had the same problem until I uploaded attrs.xml from the samples, following instructions here: http://www.mail-archive.com/[email protected]/msg34088.html . I used the same code above, but now I'm getting another error. Here's the part with the problem:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
The error is for obtainStyledAttributes, and is:
The method obtainStyledAttributes(int[]) is undefined for the type ImageAdapter
Any ideas?
Thanks ahead of time...

@Collene: you probably have ImageAdapter in a separate file and not as an inner class of HelloGalery? obtainStyledAttributes() is a method of the Context class so you have to change the code like so:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = c.obtainStyledAttributes(R.styleable.default_gallery);
Complete solution can be found in this thread: http://www.mail-archive.com/[email protected]/msg11862.html

Thank you so much for your help David B. I can see now that the tutorial left off the letter "c" there, and eclipse, while awesome, wasn't really helping me out with diagnosing the problem.

Related

[Resolved] [Q] Android App Problem (Linking list items to the android market)

Hey guys,
I need some help with my first app.
I cannot post this in the Anddev section because of my low post count, so I apologize that this goes here.
I want to link some list positions to the respective android market pages. My current code looks like this:
Code:
package com.asm.reader;
import java.util.ArrayList;
import java.util.Arrays;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
public class TitlesActivity extends ListActivity {
/** Called when the activity is first created. */
String[] links = {
"Get Full Version", "Get Reading Sample 2", "Get Reading Sample 3", "Get Reading Sample 4", "Get Reading Sample 5",
"Get Story 2", "Get Story 3", "Get Story 4", "Get Story 5"};
private ArrayAdapter<String> adapter;
private String selectedItem;
private final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OnItemClickListener itemListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position,
long arg3) {
}
};
ArrayList<String> list = new ArrayList<String>(Arrays.asList(links));
adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
list);
setListAdapter(adapter);
getListView().setOnItemClickListener(itemListener);
}
}
The dev guide says I have to do this:
Code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
But how do I set it with the right position?
Thanks a lot in advance, I hope you guys can help me out a little bit.
-----
edit: i got it
Please post how you did it!

[Q] Joystick Problem (java)

Hey, I'm MakyOnCover and please sorry my English!
I'm trying to make a Android Game in java, but I'm having problems with some kind of joystick I'm trying to denvelop!
The situation is this: the bitmap named joystick1 is not creating when I pressed the screen, so I would like to know why and how can I resolve this problem?
Thank you for your attention!
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
public class Class1 extends Activity implements OnTouchListener{
/** Called when the activity is first created. */
GameView a;
boolean toque;
float x, y, jposx, jposy;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
a = new GameView(this);
a.setOnTouchListener(this);
setContentView(new GameView(this));
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
x = event.getX();
y = event.getY();
return false;
}
public class GameView extends SurfaceView implements Runnable{
private Bitmap joystick1,joystick2;
private Bitmap shot = BitmapFactory.decodeResource(getResources(),R.drawable.shot);
Class1 e;
SurfaceHolder a;
Thread thread1 = null;
boolean correr = true;
public GameView(Context context){
super (context);
a = getHolder();
thread1 = new Thread(this);
thread1.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while(correr){
if(!a.getSurface().isValid())
continue;
Canvas canvas = a.lockCanvas();
joystick2 = BitmapFactory.decodeResource(getResources(),R.drawable.joystick2);
canvas.drawBitmap(joystick2,16,16,null);
if (x != 0 && y != 0){
joystick1 = BitmapFactory.decodeResource(getResources(),R.drawable.joystick1);
canvas.drawBitmap(joystick1,x,y,null);
}
canvas.drawBitmap(shot,0 + 20,canvas.getHeight() - shot.getHeight() - 18,null);
a.unlockCanvasAndPost(canvas);
}
}
}
}

[APP]2 java files dosen't work

Hi people.
I'm new in JAVA develop, and I'm trying do a simple game.
I tryed to work with 2 separated java files, but I don't know what I'm doing wrong. Example:
File "TesteActivity.java"
package pack.teste;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TesteActivity extends Activity {
test1 test = new test1();
public TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView)findViewById(R.id.maoe);
text.setText(test.hahae);
}
}
File "test1.java"
package pack.teste;
public class test1 {
TesteActivity test = new TesteActivity();
public String hahae = "maoe";
}
And dosen't work. Somebody can help me?
Thanks

HELP - Image Gallery In gridview to display images from spicifc folder on sdcard

I have done a lot of searching and I have come up with this code to try and display images that are located in a Folder on my SDCard. The folder is located at /.data/ToDo/.nomedia/ (I am trying to hide this images from the Main Android Gallery) The Code seems to run fine, i don't get any errors, but it's just not displaying the images. I was hoping someone could tell me what I am missing. Any Help would be greatly appreciated!!
Here is my GalleryActivity
Code:
import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
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.AdapterView.OnItemClickListener;
public class GalleryActivity extends Activity {
/** Called when the activity is first created. */
private Cursor imagecursor, actualimagecursor, cursor;
private int image_column_index, actual_image_column_index;
File sdCardDir = Environment.getExternalStorageDirectory(); //SDCard Location
String imagesDir = ("sdCardDir" + "/.data/ToDo/.nomedia/"); //Path to Images
GridView imagegrid;
private int count;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
init_phone_image_grid();
}
private void init_phone_image_grid() {
String[] img = { MediaStore.Images.Media._ID };
imagecursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, MediaStore.Images.Media.DATA + " like ? ", new String[] {imagesDir}, null);
image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
count = imagecursor.getCount();
imagegrid = (GridView) findViewById(R.id.sdcard);
imagegrid.setAdapter(new ImageAdapter(getApplicationContext()));
imagegrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
System.gc();
String[] proj = { MediaStore.Images.Media.DATA };
actualimagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,null, null, null);
actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToPosition(position);
String i = actualimagecursor.getString(actual_image_column_index);
System.gc();
Intent intent = new Intent(getApplicationContext(), GalleryFlow.class);
intent.putExtra("filename", i);
startActivity(intent);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position,View convertView,ViewGroup parent) {
System.gc();
ImageView i = new ImageView(mContext.getApplicationContext());
if (convertView == null) {
imagecursor.moveToPosition(position);
int id = imagecursor.getInt(image_column_index);
int imageID = 0;
Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
String url = uri.toString();
// Set the content of the image based on the image URI
int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
//i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID)));
i.setImageBitmap(b);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
}
else {
i = (ImageView) convertView;
}
return i;
}
}
}

[GUIDE] How to control mod from other app

Hello Guys I am Back with guide.Generally i am going to show how to control mod from other app i think you have seen in rom etc when we click show toggle it show toggle but when we click on disable toggle it disable toggle what is that how to do that let gonna do.Basically you should have basic android programming knowledge and how to make java into smali how to put it into the apk and debug.This guide i created because of @ShadeSK request so i created otherwise i wont . Okay Lets start.
Instruction
First of all create android project in your ide . Then make class which extends PreferenceActivity then make xml name setting then addPreferencesFromResource(id_to_xml) then make checkbox in the xml then populate the checkbox from the java class you can populate by
HTML:
CheckBoxPreference mClockColor = (ColorPickerPreference) findPreference(" in the xml which you have declared as key");
then make class FireSender and add content
HTML:
package com.androidfire;
import android.content.Context;
import android.content.Intent;
public class FireSender {
public static void mailTo(Context c,String id,boolean value) {
Intent intent = new Intent();
intent.setAction(id);
intent.putExtra(id,value);
c.sendBroadcast(intent);
}
}
then make another class named FireObserver add content
HTML:
/**
* AndroidFire 2015
* All files of AndroidFire are free to use reproduce utilise
* fork re use change package name and class name as you want
* (( but )) please give credit
*/
package com.androidfire;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import static android.content.SharedPreferences.*;
public class FireObserver {
/**
* Use this class as brain don't touch any file maybe FC or etc
*/
// Context must be passed other wise cant do anything
private Context mContext;
// Specific url for class
private String mSPECIFIC_URL;
// Required to get data from this
public BroadcastReceiver mBroadcastReceiver;
// Need to save data so we need it
public SharedPreferences mSPHelper;
// This is it status of that thing
private boolean mStatus;
/**
* Passed these parameter to this class otherwise it will wont work
* [user=955119]@param[/user] context set specific context
* [user=955119]@param[/user] Specific_url this means you have to set id like com.bla (This is most important thing
* you have to add unique for one mod)
* [user=955119]@param[/user] observerListener default value is this and implement it on the class
*/
public FireObserver(Context context,String Specific_url, final ObserverListener observerListener) {
setContext(context);
setSPECIFIC_URL(Specific_url);
mSPHelper = getContext().getSharedPreferences("AndroidFire",Context.MODE_PRIVATE);
mStatus = mSPHelper.getBoolean(Specific_url, true);
mSPHelper.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
[user=439709]@override[/user]
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
mStatus = sharedPreferences.getBoolean(getSPECIFIC_URL(), true);
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
}
});
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
mBroadcastReceiver = new BroadcastReceiver() {
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
boolean status = intent.getBooleanExtra(getSPECIFIC_URL(),true);
mStatus = status;
SharedPreferences.Editor ed = mSPHelper.edit();
ed.putBoolean(getSPECIFIC_URL(),status);
ed.apply();
}
};
context.registerReceiver(mBroadcastReceiver,new IntentFilter(Specific_url));
}
public Context getContext() {
return mContext;
}
public void setContext(Context mContext) {
this.mContext = mContext;
}
public String getSPECIFIC_URL() {
return mSPECIFIC_URL;
}
public void setSPECIFIC_URL(String mSPECIFIC_URL) {
this.mSPECIFIC_URL = mSPECIFIC_URL;
}
public interface ObserverListener {
public void onEnabled();
public void onDisabled();
}
}
then in the mod class that you have prepare go to that class as in this i have TestText
then declare FireObserver as
HTML:
FireObserver fireObserver = new FireObserver(getContext(),"com.SimpleText",this);
getContext(); means you have to pass context
then com.SimpleText means the url you have to register according mod like com.androidfire.CLOCK_ON_STATUSBAR etc
this means you have to implement FireObserver.ObserverListener into class on the method onEnabled declare that what you want to do if the it is checked on the other hand onDisbaled is opposite in case of my i want change the visibility.
then go the main class where you have extend PreferanceActivity then
add
HTML:
if (Cb.isChecked()) {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",true);
}
else {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",false);
}
then compile it and attached to pulled out three smali mod one , FireSender and FireObserver then attached to the apk where you want to add then install apk that you have made and run the app you have modify and check does it work if does not work give me the source i will find your error
AndroidFire said:
Hello Guys I am Back with guide.Generally i am going to show how to control mod from other app i think you have seen in rom etc when we click show toggle it show toggle but when we click on disable toggle it disable toggle what is that how to do that let gonna do.Basically you should have basic android programming knowledge and how to make java into smali how to put it into the apk and debug.This guide i created because of @ShadeSK request so i created otherwise i wont . Okay Lets start.
Instruction
First of all create android project in your ide . Then make class which extends PreferenceActivity then make xml name setting then addPreferencesFromResource(id_to_xml) then make checkbox in the xml then populate the checkbox from the java class you can populate by
HTML:
CheckBoxPreference mClockColor = (ColorPickerPreference) findPreference(" in the xml which you have declared as key");
then make class FireSender and add content
HTML:
package com.androidfire;
import android.content.Context;
import android.content.Intent;
public class FireSender {
public static void mailTo(Context c,String id,boolean value) {
Intent intent = new Intent();
intent.setAction(id);
intent.putExtra(id,value);
c.sendBroadcast(intent);
}
}
then make another class named FireObserver add content
HTML:
/**
* AndroidFire 2015
* All files of AndroidFire are free to use reproduce utilise
* fork re use change package name and class name as you want
* (( but )) please give credit
*/
package com.androidfire;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import static android.content.SharedPreferences.*;
public class FireObserver {
/**
* Use this class as brain don't touch any file maybe FC or etc
*/
// Context must be passed other wise cant do anything
private Context mContext;
// Specific url for class
private String mSPECIFIC_URL;
// Required to get data from this
public BroadcastReceiver mBroadcastReceiver;
// Need to save data so we need it
public SharedPreferences mSPHelper;
// This is it status of that thing
private boolean mStatus;
/**
* Passed these parameter to this class otherwise it will wont work
* [user=955119]@param[/user] context set specific context
* [user=955119]@param[/user] Specific_url this means you have to set id like com.bla (This is most important thing
* you have to add unique for one mod)
* [user=955119]@param[/user] observerListener default value is this and implement it on the class
*/
public FireObserver(Context context,String Specific_url, final ObserverListener observerListener) {
setContext(context);
setSPECIFIC_URL(Specific_url);
mSPHelper = getContext().getSharedPreferences("AndroidFire",Context.MODE_PRIVATE);
mStatus = mSPHelper.getBoolean(Specific_url, true);
mSPHelper.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
[user=439709]@override[/user]
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
mStatus = sharedPreferences.getBoolean(getSPECIFIC_URL(), true);
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
}
});
if (mStatus) {
observerListener.onEnabled();
}
else if (!mStatus) {
observerListener.onDisabled();
}
mBroadcastReceiver = new BroadcastReceiver() {
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
boolean status = intent.getBooleanExtra(getSPECIFIC_URL(),true);
mStatus = status;
SharedPreferences.Editor ed = mSPHelper.edit();
ed.putBoolean(getSPECIFIC_URL(),status);
ed.apply();
}
};
context.registerReceiver(mBroadcastReceiver,new IntentFilter(Specific_url));
}
public Context getContext() {
return mContext;
}
public void setContext(Context mContext) {
this.mContext = mContext;
}
public String getSPECIFIC_URL() {
return mSPECIFIC_URL;
}
public void setSPECIFIC_URL(String mSPECIFIC_URL) {
this.mSPECIFIC_URL = mSPECIFIC_URL;
}
public interface ObserverListener {
public void onEnabled();
public void onDisabled();
}
}
then in the mod class that you have prepare go to that class as in this i have TestText
then declare FireObserver as
HTML:
FireObserver fireObserver = new FireObserver(getContext(),"com.SimpleText",this);
getContext(); means you have to pass context
then com.SimpleText means the url you have to register according mod like com.androidfire.CLOCK_ON_STATUSBAR etc
this means you have to implement FireObserver.ObserverListener into class on the method onEnabled declare that what you want to do if the it is checked on the other hand onDisbaled is opposite in case of my i want change the visibility.
then go the main class where you have extend PreferanceActivity then
add
HTML:
if (Cb.isChecked()) {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",true);
}
else {
FireSender.mailTo(getApplicationContext(),"com.SimpleText",false);
}
then compile it and attached to pulled out three smali mod one , FireSender and FireObserver then attached to the apk where you want to add then install apk that you have made and run the app you have modify and check does it work if does not work give me the source i will find your error
Click to expand...
Click to collapse
No words Bro Thanks alot

Categories

Resources