You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, please. This one is quite important when developing for android, due to the following effect:
class Start < ListActivity
def onCreate(state)
super state
setContentView(R.layout.main)
getListView().setOnItemClickListener do |parent, view, pos, id|
intent = Intent.new(self, PlayGame.class)
startActivity(intent)
end
end
This code does not work, startActivity being a method of Activity is the problem (and the missing access to self). You can use the following workaround:
class Start < ListActivity
def onCreate(state)
super state
setContentView(R.layout.main)
# store a reference to 'self' to use it inside the listener
activity = self
getListView().setOnItemClickListener do |parent, view, pos, id|
intent = Intent.new(activity, PlayGame.class)
activity.startActivity(intent)
end
end
In normal java, the following code works:
void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
startActivity(new Intent(Start.this, PlayGame.class));
});
}
see issue #0 here http://groups.google.com/group/mirah/browse_thread/thread/9037d2ac8db02e47/591fd73142139862
and here
http://groups.google.com/group/mirah/browse_thread/thread/595ff2dae2dc2fc2
eg:
The text was updated successfully, but these errors were encountered: