2016-08-26 13 views
1

新しいアクティビティの前のフラグメントの文字列をクリックすると表示に問題があります。文字列は "isnull"として表示されます。新しいアクティビティの前のフラグメントのデータ表示に問題があります

ご協力いただければ幸いです。関連するコードは以下の通りです。

スキルアクティビティ:

public class Skill extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_skill); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     Intent in = getIntent(); 
     String skill = in.getStringExtra("skill"); 

     TextView dispSkill = (TextView) findViewById(R.id.skill); 
     dispSkill.setText("this skill is" + skill); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    } 

} 

RVAdapter(前のフラグメントの):

public static class AssessViewHolder extends RecyclerView.ViewHolder 
     implements View.OnClickListener { 

    CardView cv; 
    TextView assessName; 
    TextView pracName; 
    TextView required; 
    TextView reqnum; 

    AssessViewHolder(View itemView) { 
     super(itemView); 
     cv = (CardView)itemView.findViewById(R.id.cv); 
     assessName = (TextView)itemView.findViewById(R.id.assessment); 
     pracName = (TextView) itemView.findViewById(R.id.details); 
     required = (TextView) itemView.findViewById(R.id.required); 
     reqnum = (TextView) itemView.findViewById(R.id.reqnum); 

     itemView.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     Context context = v.getContext(); 

     Intent intent = new Intent(context, Skill.class); 
     context.startActivity(intent); 

     String assessName = ((TextView) v.findViewById(R.id.assessment)) 
       .getText().toString(); 
     intent.putExtra(KEY_SKILL, assessName); 

     System.out.println(assessName); 
    } 
} 
+1

を動作するはずの問題があることですエクストラがインテントに添付される前に、context.startActivity()を呼び出しています。 – jpact

答えて

1

私はあなたの質問以下のコメントで指摘したように、問題は、データが意図に添付される前に、あなたはstartActivityを呼び出しているということですので、それをonClickメソッドの最後にを移動

@Override 
public void onClick(View v) { 
    Context context = v.getContext(); 

    Intent intent = new Intent(context, Skill.class); 

    String assessName = ((TextView) v.findViewById(R.id.assessment)) 
      .getText().toString(); 
    intent.putExtra(KEY_SKILL, assessName); 

    System.out.println(assessName); 
    context.startActivity(intent); 
} 
+0

私はこれを試しました。それは私のそんなに馬鹿だった、アー!どうもありがとうございます! :) –

+0

あなたは歓迎です:)喜んでそれは働く... – jpact

0

あなたがしているもののように思える送らの意図に添付の関連情報をstartActivityを呼び出す必要がありますあなたのフラグメントやってあなたの新しいアクティビティがその情報を受け取っていない場合(特にユーザー定義の値である "isnull"の値を受け取っているため)、渡される値とキーをデバッグ(とテスト)する必要があります。

+0

私が送りたい文字列のコンソール。それはコンソールに表示されているので、すべてうまくいっていると思います。 しかし、新しいアクティビティでTextViewとして表示されていないだけです。これについての考えは? –

関連する問題