Solved

A question about setting TextView ID's in Android

Posted on 2011-03-18
3
684 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
[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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
If you use the Google Now Launcher, as an aftermarket add on, have a Samsung Note 5 and are worried about power consumption be wary of using the ultra power saving mode.  Here is what happened to me when I made the mistake of trying this out...
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

717 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