程序能运行,但是显示出来有点问题,找了半天找不到错误在哪儿,明天得上班,代码先贴过来明天再找找看。
主代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list1 = (ListView) findViewById(R.id.list1);
String[] arr1 = { "第一项", "第二项", "第三项" };
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
R.layout.array_item, arr1);
list1.setAdapter(adapter1);
ListView list2 = (ListView) findViewById(R.id.list1);
String[] arr2 = { "第1项", "第2项", "第2项" };
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
R.layout.checked_item, arr2);
list2.setAdapter(adapter2);
}
}
主xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#f00"
android:dividerHeight="2px"
android:headerDividersEnabled="false" />
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#0f0"
android:dividerHeight="2px"
android:headerDividersEnabled="false" />
</LinearLayout>
自定义xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textSize="24dp"
android:padding="10px"
android:shadowColor="#f0f"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="2"
>
</TextView>
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView1"
android:textSize="15dp"
android:padding="5px"
android:textColor="#f00"
>
</TextView>