2017-10-12 1 views
1

누군가 내가 잘못하고있는 것을 설명해 주시겠습니까? 내 데이터가 목록의 클릭 한 곳에서 클릭이 열리는 상세보기 활동으로 이전 할 수 없습니다.데이터가 새 활동으로 이전되지 않습니다.

다음은 버튼 클릭시 나타나는 코드입니다. 목록에 항목이 표시되어 있기 때문에 데이터를 볼 수 있습니다.

  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(); 
     } 

내가 말했듯이, listview는 각 항목의 ID와 이름을 표시하기 때문에이 시점에서 데이터를 사용할 수 있습니다. 나는 다음과 같은 코드를 사용하여 클릭하면

... 활동은 비어 및 항목의 토스트 아래 나는이 작업을해야 읽은하지만 난해야합니다 모든 것을에서 ID 0

@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); 

에게 온다 무언가를 떠난다. 어떤 도움을 주셔서 감사합니다. 또한 logCat 또는 기타 오류가 발생하지 않습니다.

+0

조금 더 조사한 결과 _Recipe_Id가 올바른 숫자를 읽고 있지만 조리법으로 이전되지 않는 것으로 나타났습니다. 따라서 내 조리법을 제공하고 있습니다 .recipe_id는 숫자 0입니다. 아이디어? – Koumintang

+1

확인 문제는 내 getRecipeById 코드에서 읽는 열의 간단한 실수 ... ID 열에서 읽기로 변경하여 문제가 해결됨 – Koumintang

+0

문제가 해결되면 자신의 답변을 추가하고 수락 할 수 있습니다. –

답변

0

조언의 말씀 ... 항상 데이터베이스의 올바른 열을 표시했는지 확인하십시오 ... 간단한 실수로 2 일 동안 작업을 수행 할 수 있습니다. 이 경우에는 getRecipeByID 코드에서 열 recipe_Id 대신 열 카테고리를 찾고있었습니다. 간단한 수정 이었지만 피할 수있었습니다.

관련 문제