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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:17:31+00:00 2026-05-25T10:17:31+00:00

I have the following layout file and adapter code : <?xml version=1.0 encoding=utf-8?> <RelativeLayout

  • 0

I have the following layout file and adapter code :

<?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="70dip"
android:background="@drawable/white"
android:orientation="horizontal"
android:padding="10sp">
<ImageView android:id="@+id/Logo"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip" />    
<TextView 
android:id="@+id/name"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textColor="#FF000000"
android:textStyle="bold"
android:textSize="12sp"
android:typeface="sans"  
android:layout_toRightOf="@id/Logo" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_below="@id/name"
android:textColor="#0000CC"
android:layout_toRightOf="@id/Logo" />
<TextView
android:id="@+id/address"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="12sp"
android:layout_below="@id/description"
android:textColor="#990000"
android:layout_toRightOf="@id/Logo" 
/>
</RelativeLayout>    

private void showPlaces(Cursor cursor) {

    MyCustomAdapterClass adapter = new MyCustomAdapterClass(this,cursor, true);  
setListAdapter(adapter); 

}

Can anyone tell me how I set an onclick listener to detect when someone clicks on an item in my list ?

Thank you !

EDIT Whole main :

package org.example.DatabaseImport;

import java.io.IOException;

import android.app.Activity;
import android.database.SQLException;
import android.os.Bundle;
import static android.provider.BaseColumns._ID;
import static org.example.DatabaseImport.Constants.TABLE_NAME;
import static org.example.DatabaseImport.Constants.AREA;
import static org.example.DatabaseImport.Constants.ADDRESS;
import static org.example.DatabaseImport.Constants.UNIQUEID;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.app.ListActivity;
import android.widget.SimpleCursorAdapter;

public class Main extends ListActivity {

private DataBaseHelper myDbHelper;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

    yourList.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                        Log.e("onClick",""+arg1);
                        }   
    });



    myDbHelper = new DataBaseHelper(this);

    try {

        myDbHelper.createDataBase();

} catch (IOException ioe) {

    throw new Error("Unable to create database");

}

try {

    myDbHelper.openDataBase();

}catch(SQLException sqle){

    throw sqle;

}

try {

    Cursor cursor = getPlaces();
    showPlaces(cursor);

}

finally {

myDbHelper.close();

}
}

private static String[] FROM = { _ID, AREA, ADDRESS, UNIQUEID};
private static String ORDER_BY = _ID + " ASC";

private Cursor getPlaces() {

    SQLiteDatabase db = myDbHelper.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, ORDER_BY);
    startManagingCursor(cursor);
    return cursor;

}

private static int[] TO = {R.id.name, R.id.description, R.id.address, };
private void showPlaces(Cursor cursor) {

    MyCustomAdapterClass adapter = new MyCustomAdapterClass(this,cursor, true); setListAdapter(adapter); 

}

And here is main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView 
android:id="@android:id/list"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" />
</LinearLayout>
  • 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-25T10:17:32+00:00Added an answer on May 25, 2026 at 10:17 am
    public class Main extends ListActivity implements OnItemClickListener {
    
    private DataBaseHelper myDbHelper;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myDbHelper = new DataBaseHelper(this);
    
        try {
          myDbHelper.createDataBase();
        } catch (IOException ioe) {
        throw new Error("Unable to create database");
        }
        try {
        myDbHelper.openDataBase();
        }catch(SQLException sqle){
    
        throw sqle;
    
    }
    
    try {
    
        Cursor cursor = getPlaces();
        showPlaces(cursor);
    
    }
    
    finally {
    
    myDbHelper.close();
    
    }
    }
    
    private static String[] FROM = { _ID, AREA, ADDRESS, UNIQUEID};
    private static String ORDER_BY = _ID + " ASC";
    
    private Cursor getPlaces() {
    
        SQLiteDatabase db = myDbHelper.getReadableDatabase();
        Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, ORDER_BY);
        startManagingCursor(cursor);
        return cursor;
    
    }
    
    private static int[] TO = {R.id.name, R.id.description, R.id.address, };
    private void showPlaces(Cursor cursor) {
    
        MyCustomAdapterClass adapter = new MyCustomAdapterClass(this,cursor, true); setListAdapter(adapter); 
    
    }
    
    @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            Log.e("Position",""+position);
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following layout in XML (splashscreen.xml): <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/frmLayout
I have the following layout in my xml file: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <FrameLayout android:id=@+id/logoLayout
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>
I have the following code in my layout file: <% @families = ProductFamily.find(:all, :include
I have an XML layout file that contains an EditText and a Button .
I have the following selector defined in an XML file under res/color/redeemlist_item_color.xml : <?xml
I have the following textview in a layout file, this is the full contents
I have following question. I'd like to place a file named data.xml into sdcard/appname
I have the following layout for my test suite: TestSuite1.cmd: Run my program Check

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.