0

RadioGrupのハンドルに問題があります。アプリケーションはOCRから文字列を取得します。この文字列は切り取られ、4つのラジオボタンを含むリストビューのリストのアダプタにスローされ、すでに実行されています。 http://dl.dropbox.com/u/158361/screenshot-1336249818620.png

スクリーンショットに示されているように、4つのEditTextがあり、どのラジオブトンが押されたかに応じてリスト内のアイテムを返します。raiobuttonを選択した後に文字列を送信するにはどうすればよいですか?

私のコード:

public class ocrResults extends Activity implements OnClickListener {
public static final int CAPTURE_ACTIVITY_REQUEST_CODE = 1;
public ListaAdapterResults listaAdapterRes;
public ListView id_list_tokens;     
public String[] splittedArray;
String tag = "Events";

public EditText etNazwa;
public EditText etAdres;
public EditText etGodziny;
public EditText etTelefon;
public RadioGroup radioGroup;

private View.OnClickListener onSave=new View.OnClickListener() {
   public void onClick(View v) {
      RadioSelect rs = new RadioSelect();
      rs.setItem(etNazwa.getText().toString());
      rs.setItem(etAdres.getText().toString());
      rs.setItem(etGodziny.getText().toString());
      rs.setItem(etTelefon.getText().toString());

      radioGroup=(RadioGroup)findViewById(R.id.group);

      switch (radioGroup.getCheckedRadioButtonId()) {
       case R.id.rbName:
           rs.setType("rbName");
           //etNazwa.setText(splittedArray[pos]);
           break;
       case R.id.rbAdres:
           rs.setType("rbAdres");
           break;
       case R.id.rbGodziny:
           rs.setType("rbGodziny");
           break;
       case R.id.rbTelefon:
           rs.setType("rbTelefon");
           break;
      }
      etNazwa.setText("");
      etAdres.setText("");
      etGodziny.setText("");
      etTelefon.setText("");
      radioGroup.clearCheck();
      Log.d(tag," potwierdz");
  }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.ocrresultsactivity);
   setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

   id_list_tokens = (ListView)findViewById(R.id.id_list_tokens);
   etNazwa  =(EditText)findViewById(R.id.EtResNazwa);
   etAdres  =(EditText)findViewById(R.id.EtResAdres);
   etGodziny=(EditText)findViewById(R.id.EtResGodziny);
   etTelefon=(EditText)findViewById(R.id.EtResTelefon);

   View btn_Zatw1 = findViewById(R.id.btnZatw1);
    btn_Zatw1.setOnClickListener(onSave);//this
   View btn_OCRmake1 = findViewById(R.id.btnOCRmake1);
    btn_OCRmake1.setOnClickListener(this);
   View btn_backtomain1 = findViewById(R.id.btnbacktomain1);
    btn_backtomain1.setOnClickListener(this);
   }
   @Override
   public void onClick(View v) {
  switch (v.getId()){
     case R.id.btnOCRmake1:
        Intent myIntent = new Intent(ocrResults.this, CaptureActivity.class);
        startActivityForResult(myIntent, CAPTURE_ACTIVITY_REQUEST_CODE);
        break;
     case R.id.btnbacktomain1:
        startActivity(new Intent(ocrResults.this, and4ph.class));
        finish();
        break;
  }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
        if (CAPTURE_ACTIVITY_REQUEST_CODE == requestCode) {
            String response = data.getStringExtra(edu.sfsu.cs.orange.ocr.CaptureActivity.RESPONSE);
            insertResponse(response);
        }
   }
    }
    private void insertResponse(String response) {
    String strResult = response;
    splittedArray = strResult.split(" ");   //(strResult, ' ');
    Context context = getApplicationContext();

    initListViewResp();
    }
    void initListViewResp() {           //Inicjalizacja ListView
    listaAdapterRes = new ListaAdapterResults(this, splittedArray);
    id_list_tokens.setAdapter(listaAdapterRes);

    //      if (mbutton[0] == true) { 
    //      mbutton[0]=holder.rb_Name;
    //       } else {
    //             // Get the ViewHolder back to get fast access to the ImageView.
    //             holder = (ViewHolder) convertView.getTag();
    //             holder.dealImage.setBackgroundColor(Color.WHITE);
    //             dealImage = holder.dealImage;
    //         }


    id_list_tokens.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
          Toast.makeText(getApplicationContext(), splittedArray[pos], Toast.LENGTH_SHORT).show();
        }
    });
    //getCheckedRadioButtonId();
    updateListView();
}
private void updateListView() {
    listaAdapterRes.notifyDataSetChanged();
}    
    }

そして私のアダプター:

public class ListaAdapterResults extends ArrayAdapter<String> {
    String tag = "Events";
    private Activity context;
    private String[] splittedArray;

    public ListaAdapterResults(Activity context, String[] splittedArray){
        super(context, R.layout.wiersz_tokenu, splittedArray);
        this.context        = context;
        this.splittedArray  = splittedArray;
    }
    public long getItemId(int position) {
        return position;
    }
    static class ViewHolder {
        private TextView     tv_Token;
        private RadioButton rb_Name;
        private RadioButton rb_Adres;
        private RadioButton rb_Godziny;
        private RadioButton rb_Telefon;
        private RadioGroup rgroup;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d(tag," 3");
        View rowView = convertView;
        ViewHolder holder= null;
        RadioButton[] mbutton = null;

        if(rowView == null) {
          LayoutInflater inflator = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          rowView = inflator.inflate(R.layout.wiersz_tokenu, parent, false);
          holder = new ViewHolder();
          holder.rgroup     = (RadioGroup) rowView.findViewById(R.id.group);
          holder.tv_Token   = (TextView) rowView.findViewById(R.id.tvToken);

          holder.rb_Name    = (RadioButton)rowView.findViewById(R.id.rbName);
          holder.rb_Adres   = (RadioButton)rowView.findViewById(R.id.rbAdres);
          holder.rb_Godziny = (RadioButton)rowView.findViewById(R.id.rbGodziny);
          holder.rb_Telefon = (RadioButton)rowView.findViewById(R.id.rbTelefon);

          mbutton=new RadioButton[4];
            mbutton[0]=holder.rb_Name;
            mbutton[1]=holder.rb_Adres;
            mbutton[2]=holder.rb_Godziny;
            mbutton[3]=holder.rb_Telefon;

          for(int i=0;  i<4; i++) {
              mbutton[i]=new RadioButton(context);
              //mbutton[l].setText("test"+l);
              //holder.rgroup.addView(mbutton[i]);
          }

          holder.rgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
               public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) {

                   for(int i=0; i<mRadioGroup.getChildCount(); i++) {

                       RadioButton rbtn = (RadioButton) mRadioGroup.getChildAt(i);
                       //int t=table.indexOfChild(table_row);   //System.out.println(t);

                       int t = mRadioGroup.getId();
                       System.out.println(t);

                       if(rbtn.getId() == checkedId) {
                           String text = rbtn.getText().toString();
                           // do something with text
                           //etNazwa.setText(text);

                           RadioSelect rs = new RadioSelect();
//                        rs.setItem(etNazwa.getText().toString());
//                        rs.setItem(etAdres.getText().toString());
//                        rs.setItem(etGodziny.getText().toString());
//                        rs.setItem(etTelefon.getText().toString());
//                        mRadioGroup=(RadioGroup)findViewById(R.id.radioGroupTypET);

                          switch (mRadioGroup.getCheckedRadioButtonId()) {
                           case R.id.rbName:
                               rs.setType("rbName");
                                     //String text = rbtn.getText().toString();
                                     //etNazwa.setText(text);
                               break;
                           case R.id.rbAdres:
                               rs.setType("rbAdres");
                               break;
                           case R.id.rbGodziny:
                               rs.setType("rbGodziny");
                               break;
                           case R.id.rbTelefon:
                               rs.setType("rbTelefon");
                               break;
                          }
                          Log.d(text," radioButtonSelect");
                          return;
                        }
                    }
                }
          });
          rowView.setTag(holder);
          Log.d(tag,"me");
       } else {
          holder = (ViewHolder) convertView.getTag();
//        mbutton = holder.rgroup;
          Log.d(tag,"meeee");
       }
       ViewHolder holder1 = (ViewHolder) rowView.getTag();
       holder1.tv_Token.setText(splittedArray[position]);
       Log.d(tag," event7");

       holder.tv_Token.setText(splittedArray[position]);
       holder.rb_Name.setTag(new Integer(position));
       holder.rb_Adres.setTag(new Integer(position));
       holder.rb_Godziny.setTag(new Integer(position));
       holder.rb_Telefon.setTag(new Integer(position));
//      public void onCheckedChanged(RadioGroup rgroup,int checkedId){  }
      return rowView;
    }
}
4

1 に答える 1

0

holder.rgroup.setOnCheckedChangeListenereditTextの設定値のgetViewメソッド。例えば

  String text = rbtn.getText().toString();
     etNazwa.setText(text);

このコードはコメントされているようですが、パラメータが間違っています。あなたが持っているetNazwa.setText(response);とそれはする必要があります etNazwa.setText(text);

于 2012-05-23T09:46:55.930 に答える