0

以下のコードを実行すると、seekBar の値を変更するまで、すべてうまくいきます。onProgressChange は、myValue のテキストの値を変更します。強制的に閉じると、以下のログの猫のエントリが表示されます。

デバッグ中にスローされた例外は、期待される ID 2 (myValue であることがわかります) が見つからないことを示していました。ご意見をお聞かせください。ありがとう

04-06 18:15:38.576: E/AndroidRuntime(25164):android.content.res.Resources$NotFoundException: String resource ID #0x2f
04-06 18:15:38.576: E/AndroidRuntime(25164):    at android.content.res.Resources.getText(Resources.java:201)
04-06 18:15:38.576: E/AndroidRuntime(25164):    at android.widget.TextView.setText(TextView.java:2877)
04-06 18:15:38.576: E/AndroidRuntime(25164):    at thisPackage.Tabs.CustomSeekBar.onProgressChanged(CustomSeekBar.java:74)

ColorsActivity (メイン)

public class ColorsActivity extends Activity
{
CustomSeekBar red = new CustomSeekBar();
RelativeLayout theItem;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.seekbarlist);     
    RelativeLayout thisOne = (RelativeLayout)findViewById(R.id.mainLayout);



    attachLayout(thisOne, red, "red", 1);
    //attachLayout(thisOne, "blue", 2);
    //attachLayout(thisOne, "green", 3);

   // Amarino.connect(this, "00:11:11:21:05:53");
}
public void attachLayout(RelativeLayout layout, CustomSeekBar object, String label, int id)
{

    theItem = object.createCustomSeekBar(this, label);
    theItem.setId(id);
    RelativeLayout.LayoutParams myLayoutParams  =  new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    myLayoutParams.addRule(RelativeLayout.BELOW,id-1);
    theItem.setLayoutParams(myLayoutParams);
    layout.addView(theItem, id);
}


}

カスタムシークバー

public class CustomSeekBar implements SeekBar.OnSeekBarChangeListener {

  Context myContext;
 RelativeLayout myLayout;
  TextView myValue;
  TextView myLabel;
  SeekBar mySeekBar;

  public void CustomSeekBar(){

  }


public RelativeLayout createCustomSeekBar(Context context, String label){


    myContext = context;                
    myLayout = new RelativeLayout(myContext); 


    mySeekBar = new SeekBar(myContext);
    myLabel = new TextView(myContext);
    myValue = new TextView(myContext);  

    mySeekBar.setId(1);
    myLabel.setId(2);
    myValue.setId(3);

    RelativeLayout.LayoutParams mySeekBarParams =  new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams myLabelParams   =  new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams myValueParams   =  new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    int seekBarId =  mySeekBar.getId();
    int labelId =  myLabel.getId();

    myLabelParams.addRule(RelativeLayout.BELOW,seekBarId);
    myValueParams.addRule(RelativeLayout.BELOW,seekBarId);
    myValueParams.addRule(RelativeLayout.RIGHT_OF,labelId);

    mySeekBar.setLayoutParams(mySeekBarParams);
    myLabel.setLayoutParams(myLabelParams);
    myValue.setLayoutParams(myValueParams);

    myLabel.setText(label);
    myValue.setText("hello");       
    mySeekBar.setOnSeekBarChangeListener(this);

    myLayout.addView(myLabel);
    myLayout.addView(myValue);
    myLayout.addView(mySeekBar);


    return myLayout;

}

 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    myValue.setText(progress);      
    //Amarino.sendDataToArduino(myContext, "00:11:11:21:05:53", 'A', progress);
 }
 public void onStopTrackingTouch(SeekBar seekBar){

 }
 public void onStartTrackingTouch (SeekBar seekBar){
 }


}
4

1 に答える 1

3

テキストを int に設定しているため、Android は ID でリソースを参照しようとしていると判断します。文字列に変換progressすると、問題が解決するはずです。例Integer.toString(progress)

于 2012-04-06T23:33:59.490 に答える