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 7812409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:29:38+00:00 2026-06-02T04:29:38+00:00

Ok so I’ve been trying to get an OnItemClickListener to retrieve values from list

  • 0

Ok so I’ve been trying to get an OnItemClickListener to retrieve values from list items. At the moment the click is being registered but the values aren’t coming through. Here’re the relevant parts of my code:

public class DiarySchedule extends ListActivity implements OnClickListener
{
    private DiaryDataSource datasource;
    private static final String TAG = "MAD Diary Schedule";
    private String delTitle;
    private String delDate;
    private String delTime;
    private String editTitle;
    private String editDate;
    private String editTime;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.diary_schedule);

    datasource = new DiaryDataSource(this);
    datasource.open();

    List<DiaryEntry> values = datasource.getAllDiaryEntries();

    DiaryScheduleAdapter adapter = new DiaryScheduleAdapter(this,values);
    setListAdapter(adapter);

    registerForContextMenu(getListView());


}


public class DiaryScheduleAdapter extends ArrayAdapter<DiaryEntry>
{
    private LayoutInflater li;

    public DiaryScheduleAdapter(Context context, List<DiaryEntry> values) 
    {
        super(context, 0, values);
        li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        DiaryEntry diaryEntry = getItem(position);

        View v = convertView;
        if ( v == null ) 
        {
            v = li.inflate(R.layout.diary_schedule, null);
        }

        TextView date = (TextView)v.findViewById(R.id.scheduleListDate);
        String initialDate = diaryEntry.getDate();
        String formattedDate = ConvertToDate(initialDate);
        date.setText(formattedDate);

        TextView link = (TextView)v.findViewById(R.id.scheduleListLink);
        link.setText(" at ");

        TextView time = (TextView)v.findViewById(R.id.scheduleListTime);
        time.setText(diaryEntry.getTime());

        TextView title = (TextView)v.findViewById(R.id.scheduleListTitle);
        title.setText(diaryEntry.getTitle());

        v.setOnClickListener(new OnItemClickListener(position));

        return v;
    }

}


@Override
public boolean onCreateOptionsMenu (Menu menu)
{
    new MenuInflater(getApplication()).inflate(R.menu.diary_menu, menu);
    return (super.onCreateOptionsMenu(menu));
}

@Override
public boolean onOptionsItemSelected (MenuItem item)
{
    switch (item.getItemId())
    {
        case R.id.add:
            Intent intent = new Intent(DiarySchedule.this, DiaryAddEntry.class);
            startActivity(intent);
            break;
    }
    return super.onOptionsItemSelected(item);
}



@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) 
{
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.diary_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) 
{
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId())
    {
        case R.id.edit:
            Intent editIntent = new Intent(DiarySchedule.this, DiaryEditEntry.class);

            editTitle = (String) ((TextView) info.targetView.findViewById(R.id.scheduleListTitle)).getText();
            editDate = (String) ((TextView) info.targetView.findViewById(R.id.scheduleListDate)).getText();
            editDate = GetInfoConvertToDate(editDate);
            editTime = (String) ((TextView) info.targetView.findViewById(R.id.scheduleListTime)).getText();

            editIntent.putExtra("title", editTitle);
            editIntent.putExtra("date", editDate);
            editIntent.putExtra("time", editTime);

            startActivity(editIntent);
            break;

        case R.id.delete:
            delTitle = (String) ((TextView) info.targetView.findViewById(R.id.scheduleListTitle)).getText();
            delDate = (String) ((TextView) info.targetView.findViewById(R.id.scheduleListDate)).getText();
            delDate = GetInfoConvertToDate(delDate);
            delTime = (String) ((TextView) info.targetView.findViewById(R.id.scheduleListTime)).getText();

            Log.v(TAG, "Hopefully title is: " + delTitle + " with date of " + delDate + " and time of " + delTime);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
                .setNegativeButton("No", dialogClickListener).show();

            break;
    }
    return super.onContextItemSelected(item);
}



DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() 
{
    @Override
    public void onClick(DialogInterface dialog, int which) 
    {
        switch (which)
        {
            case DialogInterface.BUTTON_POSITIVE:
            datasource.deleteDiaryEntry(delTitle, delDate, delTime);

            // IN CASE NEED TO DELETE ALL DB ENTRIES UNCOMMENT THIS 
            // (AND COMMENT THE ABOVE METHOD)
            //datasource.deleteAll();

            Intent intent = new Intent(DiarySchedule.this, DiarySchedule.class);
            startActivity(intent);
            break;

            case DialogInterface.BUTTON_NEGATIVE:
            // No action taken
            break;
        }
    }
};



@Override
public void onClick(View v) 
{
    // TODO Auto-generated method stub

}

private class OnItemClickListener implements OnClickListener
{           
    private int mPosition;

    OnItemClickListener(int position)
    {
            mPosition = position;
    }

    @Override
    public void onClick(View v) 
    {
        Log.v(TAG, "onItemClick at position" + mPosition); 
        final String title = (String) ((TextView) findViewById(R.id.scheduleListTitle)).getText();
        System.out.println("Title is: " + title);
        String date = (String) ((TextView) findViewById(R.id.scheduleListDate)).getText();
        date = GetInfoConvertToDate(date);
        System.out.println("Date is: " + date);
        final String time = (String) ((TextView) findViewById(R.id.scheduleListTime)).getText();
        System.out.println("Time is: " + time);

        Intent descIntent = new Intent(DiarySchedule.this, DiaryDetailed.class);

        descIntent.putExtra("title", title);
        descIntent.putExtra("date", date);
        descIntent.putExtra("time", time);

        startActivity(descIntent);
    }               
}

}

When debugging it reaches the OnItemClickListener OnClick method, go through it properly but just doesn’t pick up the values, which come out empty. Any ideas? Thanks

  • 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-06-02T04:29:39+00:00Added an answer on June 2, 2026 at 4:29 am

    You are having multiple views with the same id (one on each row). When getting the value try replacing

    final String title = (String) ((TextView) findViewById(R.id.scheduleListTitle)).getText();
    

    with

    final String title = (String) ((TextView) v.findViewById(R.id.scheduleListTitle)).getText();
    

    Same thing for the other values you are trying to retrieve.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:

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.