Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:35:20+00:00 2026-05-31T22:35:20+00:00

I wanna return a particular filename from a simplecursoradapter back to the activity from

  • 0

I wanna return a particular filename from a simplecursoradapter back to the activity from which it was called.
I tried this link How communicate between Adapter and Activity and also this one Data between activity and adapter
But either didnt hel p me. I am posting both the activity code and adapter code here.Kindly help

Activity
videolist = (ListView) findViewById(R.id.VideoMusicList);
        videolist.setAdapter(adapter);

//Adapter

public class SdCardAdapter extends SimpleCursorAdapter {

static final String TAG = "[SongListAdapter]";
int position;
CheckBox media_selected;
final String SETTING_TODOLIST = "todolist";
private String chk;
private Context context;
private Object itemText;
private ArrayList<string> selectedItems = new ArrayList<string>();
// String file;
private Object convertView;
// private final List<Model> list;
int count;
ListView listview;
private List<Model> list;
private Cursor videocursor;
private LayoutInflater mInflater;
private OnClickListener mClick;
private OnCheckedChangeListener mChecked;
String file_rel_path;
String file_abs_path;
String last_file;

/**
 * The Class ViewHolder.
 */
static class ViewHolder {

    /** The sdcard_item. Layout of each item in the list view */
    RelativeLayout sdcard_item;
    LinearLayout sdcard;

    /** The title. Textview to display the song title */
    TextView media_name;

    CheckBox media_selected;
    ListView listview;
    int position;

}


public SdCardAdapter(Context context, int layout, Cursor c, String[] from,
        int[] to) {
    super(context, layout, c, from, to);

}

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final View v = super.newView(context, cursor, parent);

    final Cursor filecursor = cursor;
    final ViewHolder vh = new ViewHolder();
    vh.media_name = (TextView) v.findViewById(R.id.sdcard_title);
    position = cursor.getPosition();
    count = cursor.getCount();
    vh.media_selected = (CheckBox) v.findViewById(R.id.sdcard_checkbox);
    vh.media_selected
            .setOnCheckedChangeListener(new OnCheckedChangeListener() {

                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    // TODO Auto-generated method stub

                    System.out.println("checkbox ckicked......");
                    if (vh.media_selected.isChecked()) {
                        vh.media_selected.setId(1);
                        vh.media_selected.getId();
                        last_file = file_rel_path;
                        file_rel_path = vh.media_name.getText().toString();                         
                        Log.d("filename_........", file_rel_path);
                        v.setBackgroundColor(Color.GRAY);
                    } else if (!vh.media_selected.isChecked()) {
                        file_rel_path="";
                        vh.media_selected.setId(0);
                        vh.media_selected.getId();
                        v.setBackgroundColor(Color.BLACK);
                    }

                    Log.d("Position", "" + position);
                    for (int i = 0; i < count; i++) {

                        filecursor.moveToPosition(i);
                        file_abs_path = filecursor.getString(filecursor
                                .getColumnIndex(MediaStore.Video.Media.TITLE));

                        if (file_abs_path.equals(file_rel_path)) {

                            String file_path = filecursor.getString(filecursor
                                    .getColumnIndex(MediaStore.Video.Media.DATA));
                            Log.d("filename.......", file_path);
                        }

                    }

                }
            });

    vh.sdcard_item = (RelativeLayout) v.findViewById(R.id.sdcard_item);
    v.setTag(vh);

    return v;

}
}

//This is the string that i want to pass to my previous activity

String file_path = filecursor.getString(filecursor.getColumnIndex(MediaStore.Video.Media.DATA));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:35:21+00:00Added an answer on May 31, 2026 at 10:35 pm

    Use interface callBack :

    In SdCardAdapter class create interface :

    public interface SdCardAdapterListener
    {
        public void sendFilePath(String path);
    }
    

    Add a listener param in SdCardAdapter constructor :

    private SdCardAdapterListener delegate;
    
    public SdCardAdapter(Context context, int layout, Cursor c, String[] from,
            int[] to, SdCardAdapterListener delegate) 
    {
        super(context, layout, c, from, to);
        this.delegate = delegate;
    }
    

    In Activity :

    SdCardAdapter adapter = new SdCardAdapter(this, layout, c, from, to, new SdCardAdapterListener() 
    {
        @Override
        public void sendFilePath(String path) 
        {
            // do something with path
    
        }
    });
        videolist = (ListView) findViewById(R.id.VideoMusicList);
            videolist.setAdapter(adapter);
    

    Then, simply call delegate.sendFilePath(path) in SdCardAdapter for send to sendFilePath method in your Activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's like this, I created a UITableViewCell subclass called NewsItemCell, then I wanna use
Hello I wanna compare two lists like this a=[1,2] b=10,20] compare(a,b) will return True
I wanna return a link inside to <img> . I dont know what is
In an android app I return from the android camera a bitmap which is
I wanna have a NSString object as NSData . Later this NSData-Object should return
I wanna create the uitableview like this image . loading data from server and
I wanna go back to Place.class which shows full information of a place.. now
HI I wanna timeout session from client page,i tried below code but not able
I wanna get the Timedate value from another page using request.querystring and then use
I wanna rewrite links like index.php?page=entry&id=15&action=edit to entry/15/edit . This is how my .htaccess

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.