문제

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?

도움이 되었습니까?

해결책

Inside getView() method of adapter

yourButton.setOnClickListener(new OnClickListener() {

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

             myClickShare(v);

        }
    });

다른 팁

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);                
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top