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

The Archive Base Latest Questions

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

I a new to Android development, so this is kind of a basic question.

  • 0

I a new to Android development, so this is kind of a basic question.

I would like to implement the same behavior as in the Contacts app. You have a ListView with a series of Contacts | phone icons. There you have one behavior when you click on the contact name, and another behavior when you click on the phone icon.

Here is my code.
Any help is much appreciated.

In summary, what is wrong with the approach

switch (v.getId()) {
case R.id.imageButtonAction:

Activity Class

public class CompaniesActivity extends Activity  {

MyApp app;

ListView listCompanies;

Cursor cursor;

// Adapter and its corresponding FROM and TO statements. The number and sequence of the arguments must match in FROM / TO arguments.
SimpleCursorAdapter adapter;
static final String[] FROM = { MenuNavigationData.C_COMPANY, MenuNavigationData.C_DESCRIPTION};
static final int[] TO = { R.id.textCompany, R.id.textDescription }; //

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.companies);

    //Gets a reference to the application
    app = (MyApp) getApplication();

    // Find your views
    listCompanies = (ListView) findViewById(R.id.listCompanies);

    addButton = (Button) findViewById(R.id.buttonAdd);

    // Add actions to user interaction
    listCompanies.setOnItemClickListener(new OnItemClickListener() {
        @Override
        **public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {


            switch (v.getId()) {
                case R.id.imageButtonAction:
                    startActivity(new Intent(app, InstructionsActivity.class));
                    break;
                default:
                    int i = adapter.getItemViewType(position);
                    startActivity(new Intent(app, EditMenuNavigationActivity.class));
                    break;
            }**

        }
    });

}

Activity xml

<!-- Companies ListView-->
<ListView android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_width="match_parent"></ListView>
<ListView 
    android:id="@+id/listCompanies"
    android:layout_height="match_parent"
    android:layout_width="match_parent" 
    android:layout_weight="1"
    android:background="#5555"/>

</LinearLayout>

Row xml

  android:background="#ffff"
  android:padding="6dip">

<!-- Company TextView  -->
<TextView 
    android:id="@+id/textCompany"

    android:text="TIM"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"

    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"

    android:singleLine="true"
    android:ellipsize="marquee"

    android:textColor="#c000"
    android:textStyle="bold"
    android:textSize="25sp"/>

<!-- Description TextView  -->
<TextView 
    android:id="@+id/textDescription" 

    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 

    android:layout_below="@id/textCompany"
    android:layout_alignWithParentIfMissing="true"
    android:layout_alignParentLeft="true"

    android:singleLine="true"
    android:ellipsize="marquee"

    android:textColor="#c000"></TextView>

<!-- Action ImageView -->
<ImageView
    android:id="@+id/imageButtonAction"

    android:layout_height="wrap_content"
    android:layout_width="wrap_content"

    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"

    android:layout_gravity="right"
    android:background="@drawable/icon"/>

</RelativeLayout>
  • 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-23T12:06:36+00:00Added an answer on May 23, 2026 at 12:06 pm

    New much better approach to solve this issue elegantly, and with less code!!!

    With the following modifications, the User interface is much more responsive, no more double-clicking issues. 🙂

    Much, much less code that simply works!

    Modifications to Row xml

    Insert a Linear layout to wrap both the

    In this Linear layout, insert a tag named android:onClick=”editCompanyClick”
    This is the click handler that will be called in the Activity.

    Insert a Linear layout to wrap the

    In this Linear layout, insert a tag named android:onClick=”dialClick”
    This is the click handler that will be called in the Activity.

    Modifications to Activity class

    Remove the previous code

       listCompanies.setOnItemClickListener(new OnItemClickListener() { @Override public void    onItemClick(AdapterView arg0, View v, int position, long id) {
    
                TextView company = (TextView) v.findViewById(R.id.textCompany);
                ImageView dial = (ImageView) v.findViewById(R.id.imageButtonDTMFDial);
    
                company.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(app, EditMenuNavigationActivity.class));
                    }
                });
    
                dial.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(app, InstructionsActivity.class));
                    }
                });
            }
    

    Insert the code

    public void dialClick(View v) {
            startActivity(new Intent(app, InstructionsActivity.class));
        }
    
        public void editCompanyClick(View v) {
            startActivity(new Intent(app, EditMenuNavigationActivity.class));
    record
        }
    

    Row xml

     <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="?android:attr/listPreferredItemHeight"
    
       android:padding="6dip" android:orientation="horizontal">
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:id="@+id/linearLayout1" 
            android:orientation="vertical"
            android:onClick="editCompanyClick"
            android:layout_weight="1">
            <!-- Company TextView  -->
            <TextView android:singleLine="true" android:text="TIM" android:id="@+id/textCompany" android:ellipsize="marquee" android:layout_height="wrap_content" style="@android:style/TextAppearance.Medium" android:layout_width="match_parent" android:gravity="top"></TextView>
            <!-- Description TextView  -->
            <TextView android:singleLine="true" android:text="Chamar atendente" android:id="@+id/textDescription" android:ellipsize="marquee" android:layout_height="wrap_content" style="@android:style/TextAppearance.Small" android:layout_width="match_parent" android:gravity="bottom"></TextView>
        </LinearLayout>
        <LinearLayout 
            android:layout_height="match_parent" 
            android:id="@+id/linearLayout2"
            android:onClick="dialClick" 
            android:layout_width="wrap_content" android:layout_gravity="right">
            <!-- DTMFDial ImageView -->
            <ImageView android:layout_height="wrap_content" android:background="@drawable/icon" android:id="@+id/imageButtonDTMFDial" android:layout_gravity="right" android:layout_width="wrap_content"></ImageView>
        </LinearLayout>
       </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new to android development. I would like to know why do we have
I'm very new on Android development. I have this: AlertDialog.Builder builder = new AlertDialog.Builder(this);
I am new to Android development and I have a question regarding custom views
Being new to test based development, this question has been bugging me. How much
I'm quite new to Android development (started 2 days ago) and have been through
I am new to Android development and have been following the tutorials available on
I'm pretty new to Android development, but I have some experience with Java and
I would like to write an app on Android to upload my GPS location
I'm pretty new to Android app development, and I've been playing around with swipe
I am new at android development and java programming, but I have decided to

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.