0

これまでのところ、ListView から必要なデータを選択し、次のコードを使用して次のアクティビティを開くという難しい作業を管理してきました。

    list.setOnItemClickListener(new OnItemClickListener() {
           public void onItemClick(AdapterView<?> listView, View view, 
             int position, long id) {
           // Get the cursor, positioned to the corresponding row in the result set
           Cursor cursor = (Cursor) listView.getItemAtPosition(position);



           String playerName = 
            cursor.getString(cursor.getColumnIndexOrThrow("Player_Name"));
           Toast.makeText(getApplicationContext(),
             playerName, Toast.LENGTH_SHORT).show();
           Intent in = new Intent(context, PlayerStatsActivity.class);
           in.putExtra ("Name", playerName);
           startActivity(in);
         finish();
           }
      });

PlayerStatsActivity クラス

 public void onCreate (Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.statseditor);
     dbHelper = new PlayerStatsDatabase(this);
      dbHelper.open();
     Bundle extras = getIntent().getExtras();
     if(extras !=null){
         String value = extras.getString("Name");
     }
      //Clean all data
    //  dbHelper.deleteAllStats();
      //Add some data
      //dbHelper.insertSomeCountries();

      //Generate ListView from SQLite Database
      //displayListView();
    // list = getListView();
     String PlayerNameText = extras.getString("Name");
     btnSave2 = (Button) findViewById(R.id.btnSaveStats);
     btnClear = (Button) findViewById(R.id.btnClearStats);
    txtGoalsScored = (EditText) findViewById(R.id.txtGoal);
    txtMinutesPlayed = (EditText) findViewById(R.id.txtMinPlayed);
    txtSubstituteIn = (EditText) findViewById(R.id.txtSubIn);
    txtSubstituteOut = (EditText) findViewById(R.id.txtSubOut);
    radioSubIn = (RadioButton) findViewById (R.id.rdoSubIn);
    radioSubOut = (RadioButton) findViewById (R.id.rdoSubOut);
    playerRating = (RatingBar) findViewById (R.id.ratingBar1);
    playerName = (TextView) findViewById (R.id.textView1);
    playerName.setText(PlayerNameText);

playerName前のアクティビティから選択した文字列を に表示したいplayerName TextView。上記は私が試したものですが、PlayerNameTextnull値を返します。

私は既に持っています

     String value = extras.getString("name");
     }

これは私のplayerName文字列を取得する必要がありますこれを私のplayerNameテキストフィールドに呼び出す必要があるだけだと思いますが、方法がわかりません。

4

1 に答える 1

1

設定している最初のアクティビティで

in.putExtra ("名前", playerName);

アクセスしようとしている他のアクティビティにいる間

文字列値 = extras.getString("名前");

ある名前では大文字の N で始まり、他の名前では同じです。両方を同じにします。

編集 II:

input.putExtra ("Name", playerName); の前にこれを試してください。価値を節約しているかどうかを確認します。次に、null だけでなく、プレイヤー名を言っていることをログで確認します。

Log.d("TAG", "Value: "+ playerName);

于 2013-04-18T23:28:39.567 に答える