Try with doing some small projects :)
1 Like
I know click listener but how to get clicked position
Can you suggest
Vedang has already said how to do it.
1 Like
Is that return position
I want to get position
Yes
Why not look at the sources java for the list view?
3 Likes
From where I get or can you send here
And look for list view.java.
Reading the original components is a good way to learn and understand how AI2 works
1 Like
I hope these can give you an idea
@SimpleFunction(description = "")
public void Add(){
String[] myData = {"Visual Basic .NET", "Java", "Ruby"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, 17367043, myData);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ItemClicked(position);
}
});
}
@SimpleEvent(description = "")
public void ItemClicked(int position) {
EventDispatcher.dispatchEvent(this, "ItemClicked", position);
}
2 Likes
You're Welcome
1 Like
@Salman_Devwhen I use this code with some changes this give me error
popup.setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
OnClick(position);
}
});
@SimpleEvent(description = "")
public void OnClick(int position) {
EventDispatcher.dispatchEvent(this, "Onclick", position);
}
Error
Started Compiling Project Popup
Buildfile: /compiler/android/build.xml
javac:
[mkdir] Created dir: /compiler/android/build/zjiyT/classes
[javac] Compiling 1 source file to /compiler/android/build/zjiyT/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:59: error: expected
[javac] popup.setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener() {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:59: error: expected
[javac] popup.setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener() {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:59: error: ';' expected
[javac] popup.setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener() {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: ';' expected
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: ';' expected
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: not a statement
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: ';' expected
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: expected
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: not a statement
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:61: error: ';' expected
[javac] public void onItemClick(AdapterView parent, View view, int position, long id) {
[javac] ^
[javac] /compiler/android/src/zjiyT/com/faraz/popup/Popup.java:64: error: illegal start of type
[javac] });
[javac] ^
[javac] 11 errors
[javac] 1 warning
His code looks correct
So Why I get error
You are just copy pasting the code.
As I said, you just pasted the code, the code is not even inside any method function.
1 Like
that code was for listview you copied and pasted it in popupmenu code it is totally wrong
2 Likes