4 Replies - 3632 Views - Last Post: 14 July 2011 - 06:28 PM

#1 noviceProgrammer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-January 11

Android Activity setContentView() not working? Help....

Posted 13 July 2011 - 08:41 PM

I'm just finishing up an application. I'm re-writing it now to clean everything up.
When I redid the recipe class I did not change much, but now when I click the recipe button on the main menu,
the screen will not display the activity. There are no errors in the log cat and I put in some breakpoints and the activity fully runs, just the new screen will not display. I cannot figure this out for the life of me.

The only thing I can find are these messages in the log cat:
"07-14 03:31:51.089: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44ffbe20"
"07-14 03:31:36.940: WARN/WindowManager(59): No window to dispatch pointer action 0"

menu class

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;

public class Menu extends Activity {
    
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        
        SharedPreferences preferences = getSharedPreferences("settings", MODE_PRIVATE);
		String token = preferences.getString("cookies", "false"); // gets the user token stored from a cached login to pass to subsequent activities
		
		Button wall = (Button)findViewById(R.id.wall);
		Button recipebook = (Button)findViewById(R.id.recipebook);
		Button lists = (Button)findViewById(R.id.lists);
		Button pantry = (Button)findViewById(R.id.pantry);
		
		wall.setonclickListener(new onclickListener() {

			@Override
			public void onclick(View arg0) {
				
			}
		});
		
		recipebook.setonclickListener(new onclickListener() {

			@Override
			public void onclick(View arg0) {
				Intent intent = new Intent(Menu.this, RecipeTypeSelection.class);
				startActivity(intent);
			}
		});
		
		lists.setonclickListener(new onclickListener() {

			@Override
			public void onclick(View arg0) {
				// TODO Auto-generated method stub
			}
		});
		
		pantry.setonclickListener(new onclickListener() {

			@Override
			public void onclick(View arg0) {
				// TODO Auto-generated method stub
			}
		});
    }
}



recipe class
import java.util.ArrayList;
import java.util.List;

import com.foodal.android.Database.Meals;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

public class RecipeTypeSelection extends Activity {
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recipespinner);
		
		List<String> mealTypes = new ArrayList<String>(); // an array to store the meal types for display in the activity spinner

		DatabaseHelper helper = new DatabaseHelper(this);
	    SQLiteDatabase db = helper.getWritableDatabase();
	    
		Cursor cursor = db.query(true, Meals.MEALS_TABLE, new String[] { Meals.MEAL_TYPE }, null, 
	    		null, null, null, null, null);
	    startManagingCursor(cursor); // query the database for all the distinct meal types
	    
	    int count = cursor.getCount();
	    
	    if(count <= 0 || cursor == null) {
	    	Toast.makeText(this, "You don't have any recipes in your recipe book!", Toast.LENGTH_SHORT);
	    	finish();
	    } else {
	    	mealTypes.add("All"); // add the ability to select "all" meals from the recipe book
	    	int counter = 0;
	    
	    	cursor.moveToFirst();
	    	while(cursor.isAfterLast() == false) {  // add meal types to the array
	    		String value = cursor.getString(counter);
	    		mealTypes.add(value);
	    		cursor.moveToNext();
	    	} 
	    }
	    
	    final Spinner spinner = (Spinner) findViewById(R.id.spinner);
    	ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    			android.R.layout.simple_spinner_item, mealTypes);
    	adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    	spinner.setAdapter(adapter); 
	
    	Button button = (Button)findViewById(R.id.launchsearch);
    	button.setonclickListener(new onclickListener() {

			@Override
			public void onclick(View v) {
				// TODO Auto-generated method stub
				
			}
    	});
	}
}




view for the recipe class that contains a spinner
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    			android:padding="10dp"
    			android:layout_width="fill_parent"
    			android:layout_height="fill_parent"
    			android:background="#FFFFFF" >

	<Spinner android:id="@+id/spinner"
        	 android:layout_width="fill_parent"
        	 android:layout_height="wrap_content"/>

	<Button android:id="@+id/launchsearch"
  			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_alignParentBottom="true" />
</RelativeLayout>



Is This A Good Question/Topic? 0
  • +

Replies To: Android Activity setContentView() not working? Help....

#2 giggly kisses  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 78
  • View blog
  • Posts: 391
  • Joined: 29-March 09

Re: Android Activity setContentView() not working? Help....

Posted 13 July 2011 - 08:50 PM

Although Android uses Java as its language to develop apps in its not the Java SE api just the Android api, which is much different. A mod should come around soon and move this to the appropriate section. Sorry I couldn't be of help, I'm sure someone in the Android forum will be able to solve your problem.
Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2695
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

Re: Android Activity setContentView() not working? Help....

Posted 13 July 2011 - 08:53 PM

Next time you need something moved, feel free to use the Report button. :)

Moved to Android.
Was This Post Helpful? 0
  • +
  • -

#4 giggly kisses  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 78
  • View blog
  • Posts: 391
  • Joined: 29-March 09

Re: Android Activity setContentView() not working? Help....

Posted 13 July 2011 - 08:54 PM

View PostDogstopper, on 13 July 2011 - 09:53 PM, said:

Next time you need something moved, feel free to use the Report button. :)

Moved to Android.

OP, let me run your code and see what I can come up with.


Wasn't aware I could do that, thanks for letting me know!
Was This Post Helpful? 0
  • +
  • -

#5 noviceProgrammer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-January 11

Re: Android Activity setContentView() not working? Help....

Posted 14 July 2011 - 06:28 PM

Ha, I finally figured it out!
I was calling finish() on the activity if the recipe book was empty!
For some reason the toast to notify it was empty was not displaying so I thought
the emulator was busted.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1