Solved

A question about setting TextView ID's in Android

Posted on 2011-03-18
3
675 Views
Last Modified: 2012-05-11
Hey,

       I made a dynamic table that expands/contracts according to the data received, and it has two TextViews in each row.

What I'm trying to do is, when a person clicks a row or textview, it would send the ID of the value clicked, rather than the value itself, and the ID is a value from the database that cannot be displayed on the screen.

I have tried variations of the following method... assigning the value of the ID to another variable and us it as the id of the TextViews, but none of the variations worked... and the program just crashed, or it just didn't respond.

Can anyone help me out?

Thanks in advance!
0
Comment
Question by:errang
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 500 total points
ID: 35165556
I reckon what you have is some soft of list (1st xml) with customised row (2nd xml).

Android gives you the position in the list for each row, but the IDs in the individual row are the same for all rows.
So perhaps you should send row position rather than textview ID.

Some code would be helpful to answer this question better.
0
 

Author Comment

by:errang
ID: 35169990
TableLayout tl = (TableLayout)findViewById(R.id.past_order_table);
        /* Create a new row to be added. */
        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new LayoutParams(
                       LayoutParams.FILL_PARENT,
                       LayoutParams.WRAP_CONTENT));
             /* Create a Button to be the row-content. */
             final TextView tv = new TextView(this);
             final TextView tv1 = new TextView(this);
             for(int i = 0; i < pickup_dates.size(); i++){
            	
            	 tv.setText(pickup_dates.get(i));
            	 tv.setLayoutParams(new LayoutParams(
               			 LayoutParams.FILL_PARENT,
               			 LayoutParams.WRAP_CONTENT));
               	 tv.setPadding(0, 10, 10, 10);
               	 tv.setId(i);
               	 tv.setClickable(true);
               	 tv.setOnClickListener(new OnClickListener(){
					@Override
					public void onClick(View v) {
						
Intent selectedIntent = new Intent(getParent(), OrderDetail.class);
					     b.putString("bookingId", booking_ids.get(tv.getId()));
					     	     selectedIntent.putExtras(b);
					     
TabGroupActivity parentActivity = (Tabs)getParent();
					     
					     parentActivity.startChildActivity(newActivity, selectedIntent);
					     
					}
               		 
               	 });
               	 tr.addView(tv);
            	       	 
            	 tv1.setText(destinations.get(i));
            	 tv1.setLayoutParams(new LayoutParams(
            			 LayoutParams.FILL_PARENT,
            			 LayoutParams.WRAP_CONTENT));
            	 tv1.setPadding(0, 10, 10, 10);
            	 tv1.setId(i);
            	 tv1.setClickable(true);
            	 tv1.setOnClickListener(new OnClickListener(){
 					@Override
 					public void onClick(View v) {
 						 Intent selectedIntent = new Intent(getParent(), OrderDetail.class);
b.putString("Id", booking_ids.get(tv1.getId()));
 					     
 selectedIntent.putExtras(b);
 TabGroupActivity parentActivity = (Tabs)getParent();
 					     parentActivity.startChildActivity(newActivity, selectedIntent);

 }
                		 
                });
            	 tr.addView(tv1);
             }
   /* Add row to TableLayout. */
   tl.addView(tr,new TableLayout.LayoutParams(
             LayoutParams.FILL_PARENT,
             LayoutParams.WRAP_CONTENT));
	}

Open in new window


This is the basic version of what I have, I need to get associate the ID of what I've selected with its ID in the database.

I know how to get the ID from the database... but i just don't know how to set it as an ID for the TextViews.
0
 

Author Closing Comment

by:errang
ID: 35193443
I'm gonna see if using a HashMap makes any difference.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 38
topping1 challenge 7 51
firstChar challenge 13 84
"Native" iOS applications 4 46
Introduction Everyone is using a smartphone these days. Contacts, messages, applications, documents, bookmarks, pictures, videos and other stuff which you created and are present only on your device come under the umbrella called “Personal Data”.…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 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

19 Experts available now in Live!

Get 1:1 Help Now