Solved

Listenser event not responding

Posted on 2012-03-30
5
437 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
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:
santhanasamy 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Jpanels and Jframe 8 28
Contacts, help Android 5 37
GeoTag photo with Andriod 4 21
Place to store Android app 19 46
Introduction This article is a continuation of Part-1 as evident from the title. Please visit this page (http://www.experts-exchange.com/articles/18706/Backing-up-personal-data-on-your-Android-device-Part-1.html) to read the earlier Part -1. If y…
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
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 video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

920 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

17 Experts available now in Live!

Get 1:1 Help Now