Solved

A question about setting TextView ID's in Android

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Identity Management & Mobile Apps 5 111
Github api to fetch the number of collaborators in a git repo 1 67
Html split(text) 2 48
KNOX vs Android for Work 5 42
This is an explanation of a simple data model to help parse a JSON feed
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Suggested Courses

734 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