How do you get clicked Component?

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);
    }

Ko-fi_Icon_RGB_rounded Buy me a coffee

2 Likes

Thanks all of you and speacial thanks to @TIMAI2 or @Salman_Dev

1 Like

You're Welcome :star_struck:

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 :wink:

So Why I get error

You are just copy pasting the code.

13.08.2021_16.42.19_REC

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

@Faraz_Firoz just my opinion, learn basics, if you think you know basics, you are wrong, you cant learn it all in some weeks, its a time taking and lifetime useful thing, I myself spent many months with support of @Aarush_Kumar , @newbiedeveloper, @Pradevel to learn basics and now, I know it

human mind can be slow but, once it learns, nothing is impossible

:wink:

7 Likes

I once learned table upto 20 but now I have forgotten it :pleading_face:

3 Likes


taken from Ayn Rand Quote: β€œThe more you learn, the more you know that you know nothing.”

Taifun

9 Likes

Amen. I often joke that your knowledge is inversely proportional to the number of degrees you hold. In high school, you know everything, and by the time you have a Ph.D., you know absolutely nothing :slight_smile:.

11 Likes

true, world is full of endless knowledge and you yourself prove yourself as an idol for many people even me
:smiling_face_with_three_hearts:

1 Like

Really ? I have 0 degrees :grin: . What you think ? How knowledgeable person I am ?

4 Likes

That's why it's a joke...

6 Likes

"Experience is the only genuine knowledge"

5 Likes

I need a help from you. Can you tell this sentence to my Teacher :grin: ?
No More Home Works :grinning:

2 Likes

At the end, this topic is became wonderful :grin:

5 Likes