Solved

Listenser event not responding

Posted on 2012-03-30
5
445 Views
Last Modified: 2012-04-02
Hello there,

i have 2 buttons created and have setOnClickListeners on them. the addProduct_button is responding properly. but the delete button is not working as required.only the last row gets deleted when i clcik on the delete button. what am i doing wrong.please help.i have attached my code.

cheers
Zolf
Order.java
0
Comment
Question by:zolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Santhana
ID: 37794572
Hi zolf,

First declare this TableRow  tr & Button delete_Button  as locale variable.... I guess while adding rows dynamically  the id we are assigning to the view creating problem.(I too have little skeptic about assigning  ids to a view)...


Change  your code like this ...

private void createRow(int qty2, String productSelected2)
{
   final TableRow  tr = new TableRow(this);  

   Button delete_Button = new Button(this);  
    delete_Button .setLayoutParams(lRowParam );
   delete_Button.setGravity( Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
   delete_Button.setText("Delete");
   delete_Button.setTextSize(10);
   delete_Button.setHeight(5);
   tr.addView(delete_Button);

}
0
 

Author Comment

by:zolf
ID: 37794637
santhanasamy,

thnaks for your help once again.

>>I too have little skeptic about assigning  ids to a view
what do you suggest,is there another better way out.
0
 
LVL 8

Accepted Solution

by:
Santhana earned 500 total points
ID: 37794697
Hi zolf,

Please refer this link...
http://stackoverflow.com/questions/1714297/android-view-setidint-id-programmatically-how-to-avoid-id-conflictsAccording to View documentation

The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.
So we can use any positive integer you like, but in this case there can be some views with equivalent id's.
If we want to search for some view in hierarchy calling to setTag with some key objects may be handy.

Is there another better way out??
We can define ids.xml in res/values. You can see an exact example in android's sample code.

samples/ApiDemos/src/com/example/android/apis/RadioGroup1.java samples/ApiDemp/res/values/ids.xml
0
 

Author Closing Comment

by:zolf
ID: 37794832
thanks a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tagging and Merging on Branch 1 42
Push wifi profile to Android & IOS 1 38
Java array 21 85
data internet through mobile 14 42
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question