1

CoreStartHere.java

 public class CoreStartHere extends TabActivity {

    :
 t = getTabHost();
 t.newTabSpec("tTask");
 t.setIndicator(...);
 t.setContent(new Intent().setClass(this, T1Task.class);
 :

}

t1Task.java

    T1Task extends Activity {

 :
 onCreate(Bundle ...) {

  :
  myListview = (ListView) findViewById(R.id.hdListView);
  myEditText = (EditText) findViewById(R.id.hdEditText);
  hdItems  = newArrayList <String>();
  aa = new ArrayAdapter <String>(this, R.layout.hditemview, hdItems);
  :

  setOnKeyListener (new OnKeyListener() {

   onKey(...) {

    :
    hdItems.add(0, myEditText.getText().toString());
    aa.notifyDatasetChanged();
    :
   }
  }


 }
}

hditemview.xml

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
 class="com.a1.hd.hdRecordTaskListItemView"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:padding="10dp"
 android:scrollbars="vertical"
 android:textColor="@color/HD_Text"
 android:fadingEdge="vertical"
 />

hdRecordTaskListItemView.java

    hdRecordTaskListItemView extends TextView {

 // has 3 constructors

 // onDraw

}

hdRecordTaskListItemView 中的构造函数都没有被调用,毫不奇怪 onDraw 也没有被调用。什么不见​​了?- 任何建议或问题 - 请告诉我。文本以默认样式显示。onDraw 应该在“画布”上绘制。谢谢

4

1 回答 1

0

您必须以这种方式创建布局:

<com.a1.hd.hdRecordTaskListItemView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:padding="10dp"
 android:scrollbars="vertical"
 android:textColor="@color/HD_Text"
 android:fadingEdge="vertical"
 />

在通过 XML 文件构建布局时,您使用诸如EditTextTextView类的元素,您不必提供它们的完整名称(例如android.widget.TextView),因为 android 会识别它们;但是,当您定义自己的视图时,您必须指明要显示的类的完整名称,在这种情况下是com.a1.hd.hdRecordTaskListItemView.

于 2010-06-19T22:09:10.063 回答