Solved

A question about setting TextView ID's in Android

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
This is an explanation of a simple data model to help parse a JSON feed
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 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