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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:32:52+00:00 2026-06-15T13:32:52+00:00

i create custom list but when i run this, application crash , what is

  • 0

i create custom list but when i run this, application crash , what is problem in it , please tell me.
and i wand to the functionally , when i press “+” button , it increase the count of EditText by one and when i press “-” button then it decrease the count of EditText by one ..
any one tell me what is the problem whit this piece of code . which create custom list ..

list XML file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >



     <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

    </ListView>

</RelativeLayout>

container XML file , which contain the button etc

<?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="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="1kg" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="5" >

        <Button
            android:id="@+id/btnSubtract "
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="-" />

        <EditText
            android:id="@+id/etQuantity"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:ems="10"
            android:inputType="number" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/btnAdd"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="+" />
    </LinearLayout>

</LinearLayout>

main java class

package com.example.custoplist;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends ListActivity {
    String[] itemsList= {"1/2 kg","1 kg", "5 kg", "10 kg", "16 kg"};
    String[] itemQuantity = new String[5];

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

        setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,android.R.id.text1,itemsList));

    }
    private class MyAdapter extends ArrayAdapter<String>{

        public MyAdapter(Context context, int resource, int textViewResourceId,
                String[] objects) {
            super(context, resource, textViewResourceId, objects);
            // TODO Auto-generated constructor stub
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            //return super.getView(position, convertView, parent);

            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row = inflater.inflate(R.layout.content, parent, false);
            TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
            EditText etQuantity = (EditText) findViewById(R.id.etQuantity);
            Button btnAdd = (Button) findViewById(R.id.btnAdd);
            Button btnsSubtract = (Button) findViewById(R.id.btnSubtract);
            tvTitle.setText(itemsList[position]);   
            return row;
        }   
    }
}
  • 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-15T13:32:54+00:00Added an answer on June 15, 2026 at 1:32 pm

    change these lines

            TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
            EditText etQuantity = (EditText) findViewById(R.id.etQuantity);
            Button btnAdd = (Button) findViewById(R.id.btnAdd);
            Button btnsSubtract = (Button) findViewById(R.id.btnSubtract);
    

    with

            TextView tvTitle = (TextView) row.findViewById(R.id.tvTitle);
            EditText etQuantity = (EditText) row.findViewById(R.id.etQuantity);
            Button btnAdd = (Button) row.findViewById(R.id.btnAdd);
            Button btnsSubtract = (Button) row.findViewById(R.id.btnSubtract);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this code to create a custom list view. It uses an
I want to create a custom list in Flex for an interface prototype. The
I am using VSeWSS 1.3 to create a custom list definition scoped to 'Site'.
I am trying to create a custom context processor which will render a list
Any ideas on how to create a custom player that would stream a list
I need to create a List of a custom type with properties of type
I have an unmanaged c++ application that provides a custom _matherr handler. When this
For a hw assignment, we were supposed to create a custom button to get
I'm trying to create a small application to setup fresh windows 7 systems. This
This is a custom ORM thing we're working on. It's not awesome, but it's

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.