2017-11-15 8 views
0

私はこの問題に悩まされていると思います。おそらく、私はアンドロイドフレームワークの基本的な内部動作に本当によく耳を傾けていないからです。アクティブなダイアログ内のテキストビューを変更しますか?

私はテーブルレイアウトで行を生成しています。これらの行には、ダイアログを開くonclickアクションがあります。私は今

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
     if(result != null) { 
      if(result.getContents() == null) { 
       Log.d("MainActivity", "Cancelled scan"); 
       tToast("Cancelled"); 
      } else { 
       Log.d("MainActivity", "Scanned"); 
       tToast("Scanned: " + result.getContents()); 
       // set the custom dialog components - text, image and button 
       TextView uIsbn = (TextView) getActivity().findViewById(R.id.Uisbn); 
       uIsbn.setText(result.getContents()); 
      } 
     } else { 
      // This is important, otherwise the result will not be passed to the fragment 
      super.onActivityResult(requestCode, resultCode, data); 
     } 
    } 

titleText.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
          final Dialog dialog = new Dialog(getActivity()); 
          dialog.setContentView(R.layout.update_book); 
          dialog.setTitle("Update dialog"); 

          // set the custom dialog components - text, image and button 

          String sIsbn = "-"; 
          if (book.getIsbn() != null) { 
           sIsbn = Long.toString(book.getIsbn()); 
          } 
          TextView uIsbn = (TextView) dialog.findViewById(R.id.Uisbn); 
          uIsbn.setText(sIsbn); 
          Button readBCode = (Button) getActivity().findViewById(R.id.Uread); 
          readBCode.setOnClickListener(new View.OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            IntentIntegrator integrator = new IntentIntegrator(getActivity()); 
            integrator.initiateScan(); 
           } 
          }); 
          Button dialogButton = (Button) dialog.findViewById(R.id.Uclose); 
          // if button is clicked, close the custom dialog 
          dialogButton.setOnClickListener(new View.OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            dialog.dismiss(); 
           } 
          }); 
          dialog.show(); 
} 

ここで私はこれをクリックするreadBCodeというボタン、バーコードのスキャンを開始しており、バーコードが取得されたときに消えダイアログで:コードは次のようになりますそのアクティブなダイアログのIsbnテキストビューに入っているこの結果の文字列をプッシュバックしたいのですが、これはもちろん失敗します...どうすればそれを完了させるべきですか?

答えて

1

私は断片の中にいましたので、IntentIntegrator.forFragmentを使って、それだけでそれを解決してください。

関連する問題