Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

A question about setting TextView ID's in Android

Posted on 2011-03-18
3
Medium Priority
?
686 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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.
Suggested Courses

609 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