Java 数据未传输到新活动

Java 数据未传输到新活动,java,android,database,sqlite,data-transfer,Java,Android,Database,Sqlite,Data Transfer,我做错了什么?我无法将数据从列表中单击的位置传输到单击打开的详细视图活动 这是我的代码在按钮点击。。。这里的数据是可用的,因为列表显示了项目 RecipeRepo repo = new RecipeRepo(this); final ArrayList<HashMap<String, String>> recipeList = repo.getRecipeList(); if(recipeList.size()!=

我做错了什么?我无法将数据从列表中单击的位置传输到单击打开的详细视图活动

这是我的代码在按钮点击。。。这里的数据是可用的,因为列表显示了项目

            RecipeRepo repo = new RecipeRepo(this);

        final ArrayList<HashMap<String, String>> recipeList = repo.getRecipeList();
        if(recipeList.size()!=0) {
            ListView lv = (ListView) findViewById(R.id.list);//getListView();
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                    recipe_Id = (TextView) view.findViewById(R.id.recipe_Id);
                    String recipeId = recipe_Id.getText().toString();
                    Intent objIndent = new Intent(getApplicationContext(),RecipeDetail.class);
                    objIndent.putExtra("recipe_Id", Integer.parseInt( recipeId));
                    startActivity(objIndent);
                }
            });
            ListAdapter adapter = new SimpleAdapter( SousChef.this,recipeList, R.layout.view_recipe_entry, new String[] { "id","name"}, new int[] {R.id.recipe_Id, R.id.recipe_list_name});
            lv.setAdapter(adapter);
        }else {
            Toast.makeText(this, "No recipe!", Toast.LENGTH_SHORT).show();
        }

从我所读到的一切来看,这应该是有效的,但我必须遗漏一些东西。此外,我没有在logCat或任何东西中产生任何错误。

建议。。。始终确保在数据库中标记正确的列。。。一个简单的错误会让你花掉2天的时间。在本例中,我使用getRecipeByID代码查找列类别,而不是列配方Id。简单的修复方法,但可以避免。

Word of Advice。。。始终确保在数据库中标记正确的列。。。一个简单的错误会让你花掉2天的时间。在本例中,我使用getRecipeByID代码查找列类别,而不是列recipe\u Id。简单的修复,但本可以避免。

经过进一步研究,我发现\u recipe\u Id读取的数字正确,但没有被传输到recipe。因此,它给了我的recipe.recipe\u id一个数字0。想法?好吧,问题是我的getRecipeById代码中有一个简单的错误,在哪个列上读取。。。如果问题解决了,你可以添加你自己的答案并接受它。好吧,我可以在几天内接受它。经过进一步研究,我发现_Recipe_ID读取的数字是正确的,但它没有被转移到Recipe。因此,它给了我的recipe.recipe\u id一个数字0。想法?好吧,问题是我的getRecipeById代码中有一个简单的错误,在哪个列上读取。。。如果问题解决了,你可以添加你自己的答案并接受它。好的,我可以在几天内接受它lol
   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipe_detail);

    btnEdit = (Button) findViewById(R.id.detail_edit);
    btnClose = (Button) findViewById(R.id.detail_close);

    textName = (EditText) findViewById(R.id.detail_recipe_name);
    textIngredients = (EditText) findViewById(R.id.detail_recipe_ingredients);
    textInstruct = (EditText) findViewById(R.id.detail_recipe_instruct);
    textCookTemp = (EditText) findViewById(R.id.detail_cook_temp);
    textCookTime = (EditText) findViewById(R.id.detail_recipe_cooktime);
    textServes = (EditText) findViewById(R.id.detail_recipe_servings);

    btnEdit.setOnClickListener(this);
    btnClose.setOnClickListener(this);

    _Recipe_Id =0;
    Intent intent = getIntent();
    _Recipe_Id = intent.getIntExtra("recipe_Id", 0);
    RecipeRepo repo = new RecipeRepo(this);
    Recipe recipe = new Recipe();
    recipe = repo.getRecipeById(_Recipe_Id);

    textName.setText(recipe.name);
    Toast.makeText(this, "Recipe id is " + recipe.recipe_Id, Toast.LENGTH_SHORT).show();
    textIngredients.setText(recipe.ingredients);
    textInstruct.setText(recipe.instructions);
    textCookTemp.setText(recipe.cooktemp);
    textCookTime.setText(recipe.cooktime);
    textServes.setText(recipe.serves);