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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:59:17+00:00 2026-05-28T05:59:17+00:00

I try to create listView dynamically from code with: @Override public View getView(int position,

  • 0

I try to create listView dynamically from code with:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    ViewHolder holder;
    if (v == null) {
        LayoutInflater vi =
            (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.grid_item, null);

        holder = new ViewHolder();
        holder.one = (TextView) v.findViewById(R.id.one );
        holder.two= (TextView) v.findViewById(R.id.two);
        holder.three= (TextView) v.findViewById(R.id.three);
        holder.four= (TextView) v.findViewById(R.id.four);
        holder.five= (TextView) v.findViewById(R.id.five);
        v.setTag(holder);
    }
    else
        holder=(ViewHolder)v.getTag();

    final Custom custom = entries.get(position);
    if (custom != null) {
        holder.one .setText(custom.getOne());
        holder.two.setText(custom.getTwo());
        holder.three.setText(custom.getThree());
        holder.four.setText(custom.getFour());
        holder.five.setText(custom.getFive());
    }
    return v;
}

grid_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" >

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_marginRight="4dp" />

        <View android:id="@+id/separator" 
           android:background="#cccccc" 
           android:layout_width="1dip"
           android:layout_height="45dip"
            android:layout_marginRight="4dp"/>

    </LinearLayout>

    <TextView
        android:id="@+id/one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/linearLayout1"
        android:layout_toLeftOf="@+id/linearLayout2"
        android:text=""
        android:textSize="25dp"/>

    <TextView
        android:id="@+id/two"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/alarmTitle"
        android:layout_toRightOf="@+id/linearLayout1"
        android:layout_toLeftOf="@+id/linearLayout2"
        android:text=""
        android:textSize="16dp" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="3dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/three"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textSize="12dp" />

        <TextView
            android:id="@+id/four"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textSize="12dp" />

        <TextView
            android:id="@+id/five"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textSize="12dp" />

        <TextView
            android:id="@+id/six"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textSize="12dp" />
    </LinearLayout>

</RelativeLayout>

I want to make item in listview, in my example that is relativelayout, as clickable.
I trying with:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true">

and/or:

        v.setClickable(true);
        v.setEnabled(true); 
        v.setFocusable(true);

But this is not working.

Where I made mistake?

  • 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-28T05:59:18+00:00Added an answer on May 28, 2026 at 5:59 am

    you can add your click listener to your v view returned within the getView() method

    v.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
         }....
    

    this should work – works for me. the methods called within should be moved elsewhere. not sure if you want to implement the View.OnClickListener in the Adapter but it’s up to you i guess.

    Cheers

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

Sidebar

Related Questions

I have a ListView with an adapter extending BaseAdapter. I create a view (from
I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
Android:How to display images from the web in a ListView?I have the following code
I'm trying to create custom listview in android. When I try to access my
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,
I try to create a very simple app using windows API. I've done some
I try to create 2 buttons inside my app case WM_CREATE:{ hWnd =CreateWindowEx(NULL, LBUTTON,
i try to create an AEP for my advantage Database. I create a AEP
I try to create a form that can save a person's form data 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.