Android Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingAndroid Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 18th, 2013, 07:16 PM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
View.GONE only works once

Hi!
I have a problem with using setVisibility(View.GONE) and VISIBLE. I have a listview where I store stuff and when a list-item is clicked I use listView.setVisibility(View.GONE) and inflate a new layout to this area. In this new layout I keep information about the chosen list-item together with three buttons. The button I'm trying to get to work should take the user back to the list when clicked.

When the button is clicked I set the inflated layout to GONE and the listview to VISIBLE. This works great, and when I click an item in the list a second time it works great as well.

The problem is when I click the back-button a second time. What happens is that the listview turns visible, as it should do. But the inflated view stays visible and I have no idea why because it works the first time. I'm thinking that I might not reach this inflated view the second time because I may be outside the inflated view, but I'm not sure...

Here is my code for the "on item click" in the listview:
Code:
listView1.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view,
	            int position, long id) {
			// TODO Auto-generated method stub
			
				//Store which recipe that was clicked
				String recipe = listView1.getItemAtPosition(position).toString();
            	
            	//Search the database for the recipe and pick out the 
            	//different values it contains.
            	List<String> stuffList = datasource.getAllStuff(recipe);
            	String category = stuffList.get(0).toString();
            	String comment = stuffList.get(1).toString();
            	float numStars = Float.parseFloat(stuffList.get(2));
            	
            	//Inflate a new layout to show the recipe details in
            	ViewGroup ******* = (ViewGroup) findViewById(R.id.tab2);
            	view = LayoutInflater.from(getBaseContext()).inflate(R.layout.activity_display_recipe,
                        *******,false); //null);
            	
            	//Hide the previous layout (the list of recipes)
            	listView1.setVisibility(View.GONE);
          	  	view.setVisibility(View.VISIBLE);
            	
            	//Set the values
            	TextView tV1 = (TextView) view.findViewById(R.id.tV1);
            	TextView tV2 = (TextView) view.findViewById(R.id.tV2);
            	TextView tV3 = (TextView) view.findViewById(R.id.tV3);
            	RatingBar rB1 = (RatingBar) view.findViewById(R.id.rB1);
            	tV1.setText(recipe);
            	tV2.setText(category);
            	tV3.setText(comment);
            	rB1.setRating(numStars);
            	
            	//Add the inflated view to the tab
                *******.addView(view);
		}
      });


And here is my code for the buttons onClick function:
Code:
public void backToList(View button)
  {
	  final ListView listView1 = (ListView) findViewById(R.id.listView1);
	  final LinearLayout linLay2 = (LinearLayout) findViewById(R.id.linLay2);
	  linLay2.setVisibility(View.GONE);
	  listView1.setVisibility(View.VISIBLE);
  }


Please let me know if you need more of the code.

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingAndroid Development > View.GONE only works once

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap