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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:52:29+00:00 2026-05-14T07:52:29+00:00

I want to create a layout in such a way that on top edittext

  • 0

I want to create a layout in such a way that on top edittext and button should be there in one row.
The search text I enter in editext and click on search button. Then I want to display a custom list view where each row contains image and text.(As per the API demos example list14 I have tried). But when I run the application, button and edittext are being added to each row (i.e., Each row contains a image, text, editext, button. Can Any one guide how to resolve this issue.

Below is my xml file:

<!--
    <FrameLayout android:layout_width="wrap_content"
    android:layout_height="0dip" android:layout_weight="1"></FrameLayout>
-->
<ImageView android:id="@+id/icon" android:layout_width="48dip"
    android:layout_height="48dip" />

<TextView android:id="@+id/text" android:layout_gravity="center_vertical"
    android:layout_width="0dip" android:layout_weight="1.0"
    android:layout_height="wrap_content" />


<!--
    <EditText android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/prdsearchtb"
    android:text="@string/tb_prd_search_lbl"></EditText>
-->
<!--
    <TableLayout android:id="@+id/TableLayout01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"> <TableRow>
-->
<Button android:id="@+id/prdsrcbutton" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="@string/btn_lbl_prd_search"
    android:layout_x="2px" android:layout_y="410px"></Button>
<!-- </TableRow>
</TableLayout>

–>

and Java File:
/**
*
*/
package org.techdata.activity;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

/**
* @author jayanthg
*
*/
public class ProductSearch extends ListActivity {

private static class ProductSearchAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Bitmap mIcon1;
    private Bitmap mIcon2;

    public ProductSearchAdapter(Context context) {

        mInflater = LayoutInflater.from(context);

        // Icons bound to the rows.
        mIcon1 = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.icon48x48_1);
        mIcon2 = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.icon48x48_2);
    }

    @Override
    public int getCount() {

        return DATA.length;
    }

    @Override
    public Object getItem(int position) {

        return position;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(final int position, View convertView,
            ViewGroup parent) {
        ViewHolder holder;
        Button btn=null;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.productsearch, null);

            // Creates a ViewHolder and store references to the two children
            // views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.text);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);
            btn=(Button)convertView.findViewById(R.id.prdsrcbutton);
            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }

        // Bind the data efficiently with the holder.
        holder.text.setText(DATA[position]);
        holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);

        holder.icon.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.i("image", " u clicked on icon Position" + position);

            }
        });
        holder.text.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.i("Text", " u clicked on text Position" + position);

            }
        });

        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.i("Button","U clicked on button");

            }
        });


        return convertView;
    }

    static class ViewHolder {
        TextView text;
        ImageView icon;
    }

    private static final String[] DATA = { "Abbaye de Belloc",
            "Abbaye du Mont des Cats" };

}

ListView product_search_list;
Button srch_btn;
EditText srch_text;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setListAdapter(new ProductSearchAdapter(this));
    // setContentView(R.layout.productsearch);
    // getListView().setEmptyView(findViewById(R.id.text));
    // srch_text = (EditText)findViewById(R.id.prdsearchtb);
    // srch_btn = (Button) findViewById(R.id.prdsearchtb);
    // srch_btn.setOnClickListener(new View.OnClickListener() {
    //      
    // @Override
    // public void onClick(View v) {
    // callProductSearchAdapter();
    //
    // }
    // });

}

void callProductSearchAdapter() {
    setListAdapter(new ProductSearchAdapter(this));
}

private void createDialog(String title, String text, final Intent i) {
    if (i == null) {
        AlertDialog ad = new AlertDialog.Builder(this).setIcon(
                R.drawable.alert_dialog_icon).setPositiveButton("Ok", null)
                .setTitle(title).setMessage(text).create();
        ad.show();
    }
}

}

Regards:
Jayanth

  • 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-14T07:52:30+00:00Added an answer on May 14, 2026 at 7:52 am

    What you’re doing is modifying the layout it’s using for individual rows, that’s why the buttons are appearing on every row. What you need to do is create an XML file for the main layout with the buttons and textviews, and then nest a ListView in it. For example, create a main.xml file like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
    
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Bla"/>
    
            <EditText android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Bla"/>
    
        </LinearLayout>
    
        <ListView android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
    

    It’s important that the ID of the list view be exactly as above (@android:id/list). If you don’t use that, your customised ‘Efficient Adapter’ won’t be able to find it. Once you’ve done that, you just have to add setContentView(R.layout.main); to your onCreate method right after the super.onCreate(…) line.

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

Sidebar

Related Questions

I want to create a layout like this: On the top a TextView, after
I want to create a function that performs a function passed by parameter on
I want to create a simple http proxy server that does some very basic
It's a long one so you might want to get that cup of tea/coffee
I wanted to know if there is a better way to layout my form
I can't beleive there's no easy way to do such a basic thing like
I want to create an android Layout of which I want to instantiate several
I want to create a list with some text and a photo miniature in
Every time that I want to do a Layout, I'm getting a black layout
I'm trying to build a Chrome browser extension, that should enhance the way the

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.