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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:17:06+00:00 2026-05-29T12:17:06+00:00

Why doesn’t this work? Can Anyone tell me whats wrong with this onitemclicklistener? It

  • 0

Why doesn’t this work? Can Anyone tell me whats wrong with this onitemclicklistener? It doesn’t give me any errors, but does nothing when clicked.

public class Test extends ListActivity 
{
private CommentsDataSource datasource;


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

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

    List<Comment> values = datasource.getAllComments();

    // Use the SimpleCursorAdapter to show the
    // elements in a ListView
    ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>( this, R.layout.simple_list_item_1, values );
    setListAdapter( adapter );



// Will be called via the onClick attribute
// of the buttons in main.xml


ListView list = (ListView) findViewById(android.R.id.list);

list.setClickable(true);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() 
{

public void onItemClick(AdapterView<?> list, View view, int position, long id) 
{
    @SuppressWarnings( "unchecked" )
    ArrayAdapter<Comment> adapter = ( ArrayAdapter<Comment> ) getListAdapter();
    Comment comment = null;
    switch ( view.getId() ) 
    {
    case R.layout.simple_list_item_1:
        String s =  ((TextView)view.findViewById(android.R.id.text1)).getText().toString();
        String keyword = s.substring(s.lastIndexOf(' '));



        String uri= "smsto:" + keyword;
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
        startActivity(intent);

    }
}
});
}



public void onClick( View view ) 
{
    @SuppressWarnings( "unchecked" )
    ArrayAdapter<Comment> adapter = ( ArrayAdapter<Comment> ) getListAdapter();
    Comment comment = null;
    switch ( view.getId() ) 
    {

    case R.id.delete:
        if (getListAdapter().getCount() > 0) 
        {
            comment = ( Comment ) getListAdapter().getItem( 0 );
            datasource.deleteComment( comment );
            adapter.remove( comment );
        }
        break;

    case R.id.add:
        if (getListAdapter().getCount() > 0) 
        {
            int far = getListAdapter().getCount();
            comment = ( Comment ) getListAdapter().getItem( 0 );
            datasource.deleteComment( comment );
            adapter.remove( comment );
        }
        break;

        /*
    case R.layout.simple_list_item_1:
        {
            List<String> sms = new ArrayList<String>();
            Uri uriSMSURI = Uri.parse("content://sms/inbox");
            Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
            String address = cur.getString(cur.getColumnIndex("address"));
             String body = cur.getString(cur.getColumnIndexOrThrow("body"));
             sms.add("Number: " + address + " .Message: " + body);
        }
        break;
        */
    }
    adapter.notifyDataSetChanged();

}


@Override
protected void onResume() 
{
    datasource.open();
    super.onResume();
}

@Override
protected void onPause() 
{
    datasource.close();
    super.onPause();
}

}

Here is the main.xml file where the lstview is kept:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:background="#FFFFFF">

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="406dp"
    android:layout_y="76dp"
    android:background="#FFFFFF"
    android:clickable="true"
    android:divider="#000000"
    />

<Button
    android:id="@+id/delete"
    android:layout_width="120dp"
    android:layout_height="40dp"
    android:layout_x="21dp"
    android:layout_y="16dp"
    android:onClick="onClick"
    android:text="Delete First" />

<Button
    android:id="@+id/add"
    android:layout_width="120dp"
    android:layout_height="40dp"
    android:layout_x="174dp"
    android:layout_y="16dp"
    android:onClick="onClick"
    android:text="Delete All" />

</AbsoluteLayout>

And the xml file where the edit text is kept:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_margin="10dp"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:textColor="#000000"
android:clickable="true"
android:background="#FFFFFF"
android:minHeight="?android:attr/listPreferredItemHeight"
/>
  • 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-29T12:17:07+00:00Added an answer on May 29, 2026 at 12:17 pm

    Your edit text is clickable and fills the entire row. Clicks are handled by the edit text, so the list item click listener never fires. There isn’t any way to determine whether the user intended to click into the edit text, or click on the row.

    Add a button or something for the user to click on in each row that isn’t the edit text.

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

Sidebar

Related Questions

Why doesn't this work? I have bypassed this before but i can't remember how
Doesn't work with other modules, but to give an example. I installed Text::CSV_XS with
Does anyone know how can I replace this 2 symbol below from the string
doesn't work.. can't find any solution to prevent submit page reload only if ajax
Doesn't seem to work for me, maybe I just doing it wrong
There doesn't seem to be a dictionary.AddRange() method. Does anyone know a better way
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
Doesn't matter what I do, I simply can't get this to play a sound
Why doesn't this work: <Style TargetType=s:Substance> <Setter Property=Template> <Setter.Value> <DataTemplate> <StackPanel> <TextBlock Text={TemplateBinding Name}/>
This doesn't work: $to = 'myemail@gmail.com'; $from = 'test@test.com'; $subj = 'test'; $message =

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.