2つのテキストビューとIDなしのシークバーを保持するxmlページを作成しました。 クラスCustomSeekBarは、xmlページを基本構造として使用してこれらのオブジェクトを作成します。 私のエミュレータでtextviewsの領域を見ることができますが、テキストを設定するのに苦労しています。明らかに、私は何かが欠けている。なぜなら、CustomSeekBarクラスがどのテキストビューをテキストを設定したいのかを知る方法がないからです。IDなしのTextView setText
各テキストビューにハードコードされたIDを付けずに、個々のビューのテキストを設定するにはどうすればよいですか? ハードコードされたIDなしで言う理由は、各テキストビューに名前が付けられていれば、1つのテキストビューのテキストを変更する必要があるため、そのIDを持つテキストビューのすべてのテキストが変更されないからです。 私のcustomseekbarクラスがアクティビティとの複合関係にあるので、どのように特定のテキストビューIDを呼び出すのですか?
すべてを呼び出すアクティビティ。
public class ColorsActivity extends ListActivity {
/** Called when the activity is first created. */
//Array Adapter that will hold our ArrayList and display the items on the ListView
SeekBarAdaptor seekBarAdaptor;
//List that will host our items and allow us to modify that array adapter
ArrayList<CustomSeekBar> seekBarArrayList=null;
// TextView myValueText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seekbarlist);
//Initialize ListView
ListView lstTest= getListView();
//Initialize our ArrayList
seekBarArrayList = new ArrayList<CustomSeekBar>();
//Initialize our array adapter
seekBarAdaptor = new SeekBarAdaptor(ColorsActivity.this, R.layout.seekbars, seekBarArrayList);
CustomSeekBar red = new CustomSeekBar(this, "red", 1);
//CustomSeekBar blue = new CustomSeekBar(this, "blue");
//CustomSeekBar green = new CustomSeekBar(this, "green");
//Set the above adapter as the adapter of choice for our list
lstTest.setAdapter(seekBarAdaptor);
seekBarArrayList.add(red);
//seekBarArrayList.add(blue);
//seekBarArrayList.add(green);
Amarino.connect(this, "00:11:11:21:05:53");
}
}
CustomSeekBarクラス
public class CustomSeekBar implements SeekBar.OnSeekBarChangeListener {
Context myContext;
TextView myValue;
TextView myLabel;
SeekBar mySeekBar;
CustomSeekBar(Context context, String label, int ID){
myContext = context;
myValue = new TextView(myContext);
mySeekBar = new SeekBar(myContext);
myValue.setText(label);
mySeekBar.setOnSeekBarChangeListener(this);
}
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){
}
}
seekbarlist.xmlが
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
seekbars.xmlは、各カスタムリスト項目の構造であるカスタムリストのための私のリストビューを保持している(CustomSeekBar)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBarLayout">
<TextView
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
<SeekBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:max="255"/>
</LinearLayout>
あなたは名前がなく、私はあなたを知らない場合、あなたに答えを与えるために群衆の中であなたをどのように呼びますか? –
私は質問にフォローアップの簡単な説明を与えました。 – Spectrem