Reputation: 4821
Brand new to Android and Java...
I have a protected
method in Class2
as follows:
protected void onListClick(List 2, View view, int position, long id)
{
.....
int Count = cursor.GetInt(countIndex);
........
}
I need access the value from Count
from Class2
.
in the Class1
(where trying to access value from Class2) I have int getValue = Class2.Count;
Why is this not working?
Upvotes: 0
Views: 1698
Reputation: 1480
Count
is a local variable, so it cannot be accessed by other classes. You can make a static class member of Class2
instead.
class Class2 {
static int Count;
...
protected void onListClick(List 2/*invalid name*/, View view, int position, long id)
{
...
Count = cursor.GetInt(countIndex);
...
}
}
A suggestion for the future: name all variables and methods using camelCase
, and never with numbers or special characters. Some incorrect examples from your code: int Count
, List 2
, GetInt()
.
Upvotes: 1