I have the following code that populates a ListView with a TextView in the XML Layout file. But if I try to wrap a LinearLayout around the TextView it crashes!
Code:
setListAdapter(new ArrayAdapter<MyData>(getApplicationContext(), R.layout.articlelist, items));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MyData d = items[position];
Bundle bundle = new Bundle();
bundle.putString("theArticleText", d.getText());
Intent newIntent = new Intent(getApplicationContext(), ArticleDetail.class);
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);
}
});
Working XML:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" />
不从事XML工作:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" />
</LinearLayout>
Any ideas why this is happening??? Also what I want to do is add an icon next to each item in the list, am I heading in the right direction???
Cheers,
Mike。