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

  • Home
  • SEARCH
  • 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 6156531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:37:31+00:00 2026-05-23T20:37:31+00:00

I am using a ListView with a custom adapter for displaying items as pairs

  • 0

I am using a ListView with a custom adapter for displaying items as pairs of title/subtitle TextViews.

Unfortunately, I can select an item just by clicking on its upper half, the one occupied by the title

Here is the code I am using:

journal_list.xml

<?xml version="1.0" encoding="utf-8"?>

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawSelectorOnTop="false"
    android:background="#fff"
    android:cacheColorHint="#fff"
    android:paddingBottom="6dp"
/>

journal_list_item.xml for the list item’s layout

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:descendantFocusability="blocksDescendants"
          >
<TextView
    android:id="@+id/journal_entry_date"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textColor="#000"
    android:textSize="18sp"

    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
/>
<TextView
    android:id="@+id/journal_content"
    android:paddingLeft="28dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textSize="16sp"
    android:textColor="#555"
    android:inputType="textMultiLine"
    android:maxLines="2"
    android:minLines="1"
    android:layout_below="@id/journal_entry_date"
    android:layout_alignParentLeft="true"
/>

Also the code for the adapter:

private class JournalAdapter extends ArrayAdapter<JournalEntry> {
    Context ctxt;
    public JournalAdapter(Context ctxt) {
        super(ctxt, R.layout.journal_list_item);
        this.ctxt = ctxt;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        JournalHolder holder;
        if (row == null) {
            row = ((LayoutInflater)ctxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
                    inflate(R.layout.journal_list_item, parent, false);
            holder = new JournalHolder(row);
            row.setTag(holder);
        } else {
            holder = (JournalHolder) row.getTag();
        }
        JournalEntry crt = getItem(position);
        holder.getDate().setText(crt.dateWritten);
        holder.getContent().setText(crt.content);

        return row;
    }
}

private static class JournalHolder {
    private TextView date;
    private TextView content;
    private View base;

    public JournalHolder(View base) {
        this.base = base;
    }
    public TextView getDate() {
        if (date == null)
            date = (TextView) base.findViewById(R.id.journal_entry_date);
        return date;
    }
    public TextView getContent() {
        if (content == null)
            content = (TextView) base.findViewById(R.id.journal_content);
        return content;
    }
}

Code from the ListActivity’s onCreate() method:

private JournalAdapter adapter;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.journal_list);
    adapter = new JournalAdapter(this);
    setListAdapter(adapter);
    registerForContextMenu(getListView());
}

Also, I am calling a method called updateList() in onResume()

private void updateList() {
    adapter.clear();
    Cursor cursor = helper.listJournal(start, end);
    cursor.moveToFirst();
    JournalEntry crt;
    while (!cursor.isAfterLast()) {
        crt = new JournalEntry();
        crt.dateWritten = cursor.getString(cursor.getColumnIndex("date_written"));
        crt.content = cursor.getString(cursor.getColumnIndex("content"));
        crt.id = cursor.getInt(cursor.getColumnIndex("entry_id"));
        adapter.add(crt);
        cursor.moveToNext();
    }
    cursor.close();
    adapter.notifyDataSetChanged();
}

List item clicking is handled in the onListItemClick of my ListActivity, as follows:

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Intent intent = new Intent(this, JournalEditor.class);
    intent.setAction(Intent.ACTION_EDIT);
    intent.putExtra("entry_id", adapter.getItem(position).id);
    startActivity(intent);
}

Apparently, I am forgetting something important, and that’s why this whole weird thing happens.

I have found a similar discussion here: http://groups.google.com/group/android-developers/browse_thread/thread/5636c8ea74033657 but it wasn’t very helpful.

  • 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-23T20:37:32+00:00Added an answer on May 23, 2026 at 8:37 pm

    The problem may be from the clicking of the textviews. When you set the views of the listview items as clickable, they override the click of the listview item and the click will only work when the specific view of the item is clicked.

    If this is the case, do the following for your two textviews in the getView() function:

    TextView tv;
    tv.setFocusable(false);
    tv.setClickable(false);
    

    Then set the listview to clickable: listView1.setClickable(true);

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

Sidebar

Related Questions

I have three textviews in a row of a listview using custom adapter and
I'm trying to delete items from a ListView using a custom adapter which extends
I am using a custom adapter for my ListView as per the efficient adapter
I am getting XML data from url and displaying using a custom list adapter
I have a listView using a custom adapter. Each row contains a button and
friends, i am using following custom adapter to show textview and checboxes in listview.
I am using Custom Adapter to populate a listview which is reading from the
Hi I am using a custom Adapter class as an adapter in listview when
I am using an array list, a listView, and a custom simple adapter in
I'm using the new ASP.Net ListView control to list database items that will be

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.