简体   繁体   中英

How to set and get id of a view

I have 2 queries:

1). I want to display kind of screen lik

Heading        ImageButton1 ImageButton2
Value1                      Value2

Same way number of records

So i have used absolute layout programmatically instead of using xml, is it advisable or there is some other way?

2). At that time of displaying this view, i have to set unique Id to each record and get Id whenever any of 2 buttons pressed of any record. Can anyone tel me how is that possible? Means in short how to set and get id which button of which record is selected??

Thanks in advance.

  • Do not use absolute layout, try creating layout in XML file.

  • Since your imageButtons and values are dynamic, let's check it out this way......

    Store the values or there corresponding id's in an array, then give each imageButton id in sequence. ex first one id as 0, 2nd one id as 1 and so on......

    add OnClickListeners to these, since you will be creating in loop it will be easy,
    From listener you will be able to get the id of button clicked via v.getId().....

    Get the element from array at that particular position as that of id.... for ex.. if id is 0 get element at 0th loc, if id is 1 get element at 1st position

    If i show by array then,:

    [value1/ id of 1] - imagebutton with id 0
    [value2/ id of 2] - imagebutton with id 1
    [value3/ id of 3] - imagebutton with id 2
    [value4/ id of 4] - imagebutton with id 2



Hope this helps........

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM