Android에 익숙하지 않아서 simple_list_item_1 대신 사용자 정의 레이아웃 파일을 사용하고 싶지만 그렇게 할 수는 없습니다. 레이아웃의 각 항목에 backgroud 이미지 (layout-> custom_view.xml에 정의되어 있음)를 추가하거나 전체 페이지의 배경색을 설정하는 데 도움이됩니다. 아래 코드에서 setContentView 메소드를 사용해야합니다. 또한 아래의 .xml 파일에서 변경해야 할 사항이 있으면 알려주십시오. 다음과 같이ArrayAdapter의 사용자 정의 레이아웃을 사용할 수 없습니다.
public class Planet extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
//setContentView(R.layout.custom_view); Tried to set the view from here but the application is crashing...
String[] planet_names = new String[] {"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Sun"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, planet_names);
setListAdapter(adapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(position == 0)
{
Intent myIntent = new Intent(Planet.this, Galaxy.class);
startActivityForResult(myIntent, 0);
}
}
});
}
custom_view.xml 파일 당신은 ListActivity
의 내용 없음을 설정하지,
<?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="fill_parent"
android:background="#FFFFFF">
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>