私は、次の線形layourあります私はインスタンス化のためのビューを変更する必要があります。私はベースのためのIDを取得することは可能ですか?
<?xml version="1.0" encoding="utf-8"?>
<View
android:id="@+id/white1"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white2"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white3"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white4"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white5"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white6"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white7"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white8"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white9"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white10"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/white_mic_value"/>
<View
android:id="@+id/white11"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/half_white_mic_value"/>
<View
android:id="@+id/white12"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/half_white_mic_value"/>
<View
android:id="@+id/white13"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/half_white_mic_value"/>
<View
android:id="@+id/white14"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/half_white_mic_value"/>
<View
android:id="@+id/white15"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/half_white_mic_value"/>
<View
android:id="@+id/white16"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:background="@drawable/half_white_mic_value"/>
をし、私はそれらを使用したい、何かのように:私が試した
for(int i= 1 ; i < 17; i++){
if(soundMeter.getAmplitude() > i*viewThreshold) {
rootView.findViewById(R.id.white+).setBackgroundResource(R.drawable.white_mic_value);
}else{
rootView.findViewById(R.id.white+i).setBackgroundResource(R.drawable.half_white_mic_value);
}
}
: int id = getResources().getIdentifier("white" + i, "view", getActivity().getPackageName());
それは次のエラーでクラッシュ:
06-20 09:12:45.011: E/InputEventSender(28432): Exception dispatching finished signal.
06-20 09:12:45.011: E/MessageQueue-JNI(28432): Exception in MessageQueue callback: handleReceiveCallback
06-20 09:12:45.031: E/MessageQueue-JNI(28432): java.lang.NullPointerException
: https://s3.amazonaws.com/uploads.hipchat.com/39260/829560 /3tVsu9UkFrDlarJ/upload.png 私はそれらを動的に作成するためのロジックで行こうと考えていたが、私は、XMLを兼ね備え、固定数の要素をneing、またbutterknifeを使用して、それが高速ですので、それは、それらを注入します。だから私はちょうどXMLでそれらを残し、intの配列でそれをした:D –