Solved

Listenser event not responding

Posted on 2012-03-30
5
434 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
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:santhanasamy
Comment Utility
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
Comment Utility
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:
santhanasamy earned 500 total points
Comment Utility
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
Comment Utility
thanks a lot
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now