[android-beginners] ContextMenu Problem - how to resolve these menu items

2010-07-15 Thread kivy
Hi, I am very new to Android.

I am trying to build inflate a context menu within the sample GridView
provided on the Android dev site. Eclipse tells me that the referenced
items cannot be resolved, if someone could help find where I coded
s.th. wrong, that would be great because I am stuck at the moment.
Thanks.

I posted my entire code below. I get the error message at: `if
(item.getItemId() == R.id.menu_facebook)` and the other R.id.'s


This is the ShareGalleryView.java file:


 import android.app.Activity;
 import android.content.Context;
 import android.os.Bundle;
 import android.view.ContextMenu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.widget.BaseAdapter;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.AdapterView.AdapterContextMenuInfo;

 public class ShareGalleryView extends Activity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videogrid);

GridView vGrid=(GridView) findViewById(R.id.vgrid);
registerForContextMenu(vGrid);
vGrid.setAdapter(new VideoAdapter(this));
}

public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
  super.onCreateContextMenu(menu, v, menuInfo);
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu_gallery_share, menu);
}

public boolean onContextItemSelected (MenuItem item){
AdapterContextMenuInfo info = (AdapterContextMenuInfo)
item.getMenuInfo();
if (item.getItemId() == R.id.menu_facebook)
{
 //TODO open fb
return true;

}
else if (item.getItemId() == R.id.menu_youtube)
{
//TODO open youtube
return true;

}
else if (item.getItemId() == R.id.menu_email)
{
 //TODO open email
return true;

}
else if (item.getItemId() == R.id.menu_bluetooth)
{
// TODO send via bluetooth
return true;

}
}

public class VideoAdapter extends BaseAdapter {
private Context mContext;

public VideoAdapter(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_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_2,
R.drawable.sample_6, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_1

};
}
}

and this is the menu_gallery_share.xml file:

?xml version=1.0 encoding=utf-8?
menu xmlns:android=http://schemas.android.com/apk/res/
android
  menu xmlns:android=http://schemas.android.com/apk/res/
android
item android:id=@+id/menu_facebook
  android:title=@string/Facebook /
item android:id=@+id/menu_youtube
  android:title=@string/YouTube /
item android:id=@+id/menu_email
  android:title=@string/Email /
item android:id=@+id/menu_bluetooth
  android:title=@string/Via Bluetooth /
   /menu
/menu

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from 

Re: [android-beginners] ContextMenu Problem - how to resolve these menu items

2010-07-15 Thread Justin Anderson
I may be wrong but I don't think that item.getItemId refers to a resource
id...  I may be wrong though because I have never create a menu via XML
(though I do almost all other layouts in XML).  I usually do the menus in
code.

What I do is create a constant int variable such as:

protected static int CONTEXT_MENU_FACEBOOK_ID = 0;
protected static int CONTEXT_MENU_YOUTUBE_ID = 1;

When I create the context menu (in code) I assign the item id's that I
defined above. And then I would have my comparisons as follows:

 if (item.getItemId() == CONTEXT_MENU_FACEBOOK_ID)
{
 //TODO open fb
return true;
}
else if (item.getItemId() == CONTEXT_MENU_YOUTUBE_ID)
{
 //TODO open youtube
return true;
}

--
There are only 10 types of people in the world...
Those who know binary and those who don't.
--


On Thu, Jul 15, 2010 at 2:16 PM, kivy victoriasarabu...@gmail.com wrote:


public boolean onContextItemSelected (MenuItem item){

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en


Re: [android-beginners] ContextMenu Problem - how to resolve these menu items

2010-07-15 Thread Victoria Busse
Hey Justin, thanks for the reply, I just solved the problem it was within
the xml.file ...instead of   android:title=@string/Facebook I now
use android:title=Facebook and it works perfectly :)

On Thu, Jul 15, 2010 at 10:16 PM, Justin Anderson
janderson@gmail.comwrote:

 I may be wrong but I don't think that item.getItemId refers to a resource
 id...  I may be wrong though because I have never create a menu via XML
 (though I do almost all other layouts in XML).  I usually do the menus in
 code.

 What I do is create a constant int variable such as:

 protected static int CONTEXT_MENU_FACEBOOK_ID = 0;
 protected static int CONTEXT_MENU_YOUTUBE_ID = 1;

 When I create the context menu (in code) I assign the item id's that I
 defined above. And then I would have my comparisons as follows:

  if (item.getItemId() == CONTEXT_MENU_FACEBOOK_ID)

 {
  //TODO open fb
 return true;
 }
 else if (item.getItemId() == CONTEXT_MENU_YOUTUBE_ID)

 {
  //TODO open youtube
 return true;
 }

 --
 There are only 10 types of people in the world...
 Those who know binary and those who don't.
 --



 On Thu, Jul 15, 2010 at 2:16 PM, kivy victoriasarabu...@gmail.com wrote:


public boolean onContextItemSelected (MenuItem item){


  --
 You received this message because you are subscribed to the Google
 Groups Android Beginners group.

 NEW! Try asking and tagging your question on Stack Overflow at
 http://stackoverflow.com/questions/tagged/android

 To unsubscribe from this group, send email to
 android-beginners+unsubscr...@googlegroups.comandroid-beginners%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-beginners?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en


Re: [android-beginners] ContextMenu Problem - how to resolve these menu items

2010-07-15 Thread Kostya Vasilyev
Just a guess - the menu XML failed to compile because of a string id with a
space in it (Via Bluetooth).

16.07.2010 1:25 пользователь Victoria Busse victoriasarabu...@gmail.com
написал:

Hey Justin, thanks for the reply, I just solved the problem it was within
the xml.file ...instead of   android:title=@string/Facebook I now
use android:title=Facebook and it works perfectly :)



On Thu, Jul 15, 2010 at 10:16 PM, Justin Anderson janderson@gmail.com
wrote:

 I may be wr...

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en