我创建了一个 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" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dip"
android:paddingRight="4dip"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp" />
</LinearLayout>
我想用下面的代码填充这个布局:
package ir.smspeik.sms;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MyListView extends ListActivity {
/** Called when the activity is first created. */
TextView selection;
String[] names;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listlayout);
names = new String[] { "sunday", "monday", "tuesday", "wednesday",
"thrusday", "friday", "saturday", };
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.custom,
R.id.label, names));
selection = (TextView) findViewById(R.id.label);
}
public void onListItemClick(ListView parent, View v, int position, long id) {
selection.setText(names[position]);
}
}
我有两个警告和一个错误。警告在 xml 文件中:1. 此标签及其子标签可以替换为一个和一个复合可绘制对象 2. [辅助功能] 图像上缺少 contentDescription 属性
MyListView 中的错误 1. eclipse 不知道 android.R.layout.custom