我创建了一个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文件中: 这个标签及其子代可以用一个和一个复合画面代替 2. [辅助功能]图像上缺少contentDescription属性
MyListView中的错误 1. eclipse不知道android.R.layout.custom
答案 0 :(得分:2)
使用R.layout.custom
代替android.R.layout.custom