Question

I am parsing json and creating list. After that i have setOnItemClickListener and everything works. ListItems are with buttons. In my item layout i have put :

android:onClick="myClickShare"

and then i've created method in my class to share title.

public void myClickShare(View v) {              
        Intent sharingIntent = new Intent(
                android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = ________________________________________;
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "Subject Here");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                shareBody);
        startActivity(sharingIntent);                
}

What i wont to do is to find string of that item and put it in shareBody. I've tried to put:

Data.get(position).get(TAG_NAME)

but it can't find position of that item (i understand that i dont have list in my method so it wont work)

Can anyone help?

Était-ce utile?

La solution

Inside getView() method of adapter

yourButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // call share method here   

             myClickShare(v);

        }
    });

Autres conseils

While parsing and setting the name for list items also set the tag as String object inside getView method in adapter for that view.

Then you can use this as

public void myClickShare(View v) {              
        Intent sharingIntent = new Intent(
                android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = v.getTag();
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "Subject Here");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                shareBody);
        startActivity(sharingIntent);                
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top