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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:38:15+00:00 2026-06-14T23:38:15+00:00

I’m a newbie android.I have some problem about my mini app. You can see

  • 0

I’m a newbie android.I have some problem about my mini app.
You can see figure below:
http://i481.photobucket.com/albums/rr175/viethungit/android.png

Firstly,row 1(layout 1) appear listview when click button add in row 1, row 2(layout 2) appear, and continue…click button add in row 1 ,layout 2 appear in listview….
I try search from Mr.Google but i don’t find…
Anybody could help me!

This is layout, and activity I don’t know how to implement

add_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#EEEEEE"
    android:orientation="horizontal"
    android:padding="5dip">

    <!-- Image Item-->
    <ImageButton
            android:id="@+id/imgItem"
            android:layout_width="40dip"
            android:layout_height="40dip"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="2dp"
            android:contentDescription="@string/imgView"  />

    <!-- Name item  -->

    <EditText
        android:id="@+id/edtItem"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/imgItem"
        android:background="@drawable/bg"
        android:hint="@string/txtTitle"
        android:textSize="20dip" />   

    <!-- Button add -->
    <Button        
        android:id="@+id/btnAdd"
        android:background="@drawable/add"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"/>
    <!-- item -->
    <TextView
        android:id="@+id/txtSubtitle"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_toLeftOf="@+id/btnAdd"
        android:gravity="right|center_vertical"
        android:layout_centerVertical="true"
        android:textSize="20dip"
        android:text="@string/txtSubtitle" />

</RelativeLayout>


plus_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#EEEEEE"
    android:orientation="horizontal"
    android:padding="5dip" >

    <!-- Image Item -->
    <ImageView
        android:id="@+id/imgItem"
        android:src="@drawable/chomsao"
        android:layout_width="40dip"
        android:layout_height="40dip"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="2dp"
        android:contentDescription="@string/imgView" />

    <!-- Name Item -->
    <TextView
        android:id="@+id/edtItem"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/imgItem"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:text="@string/txtTitle"
        android:textSize="20dip" />

    <!-- Quantity Item -->
    <TextView 
        android:id="@+id/txtQtyItem"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_toRightOf="@id/edtItem"
        android:layout_marginLeft="20dp"
        android:gravity="center_vertical"
        android:textSize="20dip"
        android:text="@string/QuantityItem"/>

    <!-- Button plus -->
    <Button
        android:id="@+id/btnPlus"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/plus" />

    <!-- Button minus -->
    <Button
        android:id="@+id/btnMinus"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_centerVertical="true"
        android:layout_alignBaseline="@id/btnPlus"
        android:layout_toLeftOf="@+id/btnPlus"
        android:background="@drawable/minus" />

    <!-- Price Item -->
    <TextView
        android:id="@+id/txtSubtitle"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/btnMinus"
        android:gravity="right|center_vertical"
        android:text="@string/txtSubtitle"
        android:textSize="20dip" />

</RelativeLayout>



activity_main.xml
        <RelativeLayout 
        android:id="@+id/relative1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/relative"
        android:layout_above="@id/relative2"
        android:background="#EEEEEE"
        android:layout_marginLeft="1.5dp"
        android:layout_marginRight="1.5dp"
        android:layout_marginTop="1.5dp">

        <ListView
            android:id="@+id/listSale"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>        
    </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-06-14T23:38:17+00:00Added an answer on June 14, 2026 at 11:38 pm
    public class AndroidCustomListViewActivity extends Activity {
        private ListView myList;
        private MyAdapter myAdapter;
        private ImageView myImage;
        public static  String upload= " ";
        public static String GalleryImage;
        public ArrayList<ListItem> myItems = new ArrayList<ListItem>();
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.listandimage);
    
            myList = (ListView) findViewById(R.id.MyList);
            myImage= (ImageView)findViewById(R.id.image1);
    
            myList.setItemsCanFocus(true);
            myAdapter = new MyAdapter();
    
            ListItem listItem = new ListItem();
            listItem.textdata="@";
            listItem.caption = "";
            myItems.add(listItem);
    
            myList.setAdapter(myAdapter);
            myAdapter.notifyDataSetChanged();
    
    
        }
    
    
        public class MyAdapter extends BaseAdapter {
            private LayoutInflater mInflater;
    
            public MyAdapter() {
                mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            }
    
            public int getCount() {
                return myItems.size();
            }
    
            public ListItem getItem(int position) {
                return myItems.get(position);
            }
    
            public long getItemId(int position) {
                return position;
            }
    
            public View getView(final int position, View convertView, ViewGroup parent) {
                final ViewHolder holder;
                if (convertView == null) {
                    holder = new ViewHolder();
                    convertView = mInflater.inflate(R.layout.item, null);
                    holder.text=(TextView )convertView.findViewById(R.id.textView1); 
                    holder.captionEditText = (EditText) convertView.findViewById(R.id.ItemCaption);
    
                    holder.addOrDeleteButton = (Button) convertView.findViewById(R.id.buttonAdd);
    
                    holder.captionEditText.setFocusable(true);
                    holder.captionEditText.requestFocus();
    
                    convertView.setTag(holder);
                } else {
                    holder = (ViewHolder) convertView.getTag();
                }
    
                // Fill EditText with the value you have in data source
                // holder.captionEditText.setId(position);
                holder.text.setTag(position);
                holder.captionEditText.setTag(position);
                holder.captionEditText.setText(getItem(position).caption);
    
                holder.addOrDeleteButton.setTag(position);
    
                // / this updates tag of
                // the button view as we
                // scroll ///
    
                holder.addOrDeleteButton.setOnClickListener(new OnClickListener() {
    
                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        int tag = (Integer) view.getTag();
                        if (tag != (myItems.size() - 1)) {
                            myItems.remove(tag);
                            Log.d("GCM", "Item removed from " + tag);
                            myAdapter.notifyDataSetChanged();
                        } else {
                            ListItem listItem = new ListItem();
                            listItem.textdata="@";
                            listItem.caption = "";
                            myItems.add(listItem);
    
    
                            /*
                             * Log.d("GCM", holder.captionEditText.getText()
                             * .toString()); myItems.get((Integer)
                             * view.getTag()).caption = holder.captionEditText
                             * .getText().toString();
                             */
                            myAdapter.notifyDataSetChanged();
                            myList.setSelection(myAdapter.getCount() - 1);
                            // holder.captionEditText.setFocusable(true);
                            // holder.captionEditText.requestFocus();
    
                        }
                    }
                });
    
                holder.captionEditText.addTextChangedListener(new TextWatcher() {
    
                    public void onTextChanged(CharSequence s, int start,
                            int before, int count) {
                        // TODO Auto-generated method stub
    
                    }
    
                    public void beforeTextChanged(CharSequence s, int start,
                            int count, int after) {
                        // TODO Auto-generated method stub
    
                    }
    
                    public void afterTextChanged(Editable s) {
                        // if(position < myItems.size())
                        // getItem(position).caption = s.toString();
    
                        myItems.get((Integer) holder.captionEditText.getTag()).caption = holder.captionEditText
                                .getText().toString();
    
                    }
                });
    
                if (position != (myItems.size() - 1)) {
                    holder.addOrDeleteButton.setBackgroundResource(R.drawable.fruttarecloseicon);
                } else {
                    holder.addOrDeleteButton.setBackgroundResource(R.drawable.fruttareaddicon);
                    holder.text.setFocusable(true);
                    holder.captionEditText.setFocusable(true);
                    holder.text.requestFocus();
                    holder.captionEditText.requestFocus();
    
                }
    
                return convertView;
            }
    
        }
    
        class ViewHolder {
    
            TextView text;
            EditText captionEditText;
            Button addOrDeleteButton;
        }
    
        class ListItem {
            String textdata;
            String caption;
        }
    }
    

    use this code edit it according to your need.

    <?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"
        android:orientation="horizontal"
         >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="15dp"
            android:layout_height="50dp"
            android:text=" @"
           />
    
        <EditText
            android:id="@+id/ItemCaption"
            android:layout_width="270dp"
            android:layout_height="50dp"
            android:layout_margin="3dip"
            android:imeOptions="actionDone|flagNoExtractUi"
            android:inputType="textNoSuggestions"
            android:singleLine="true" >
        </EditText>
    
        <Button
            android:id="@+id/buttonAdd"
            android:layout_width="75dp"
            android:layout_height="50dp"
            android:layout_margin="3dip"
            />
    
    </LinearLayout>
    
    
    <?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"
        android:background="#fff"
        android:orientation="horizontal" >
    
        <ListView
            android:id="@+id/MyList"
            android:layout_width="370dp"
            android:layout_height="160dp"
            android:layout_gravity="center|top"
            android:layout_marginLeft="150dp"
            android:descendantFocusability="beforeDescendants" 
                 >
        </ListView>
    
        <ImageView
            android:id="@+id/image1"
            android:layout_width="80dp"
            android:layout_height="80dp"
    
             />
    
    </LinearLayout>
    

    mark the answer right if it was useful!!

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Does anyone know how can I replace this 2 symbol below from the string
I have been unable to fix a problem with Java Unicode and encoding. The
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.