У меня есть lisview, к которому я хочу добавить изображения. Примеры, которые я нашел ранее, показали использование simple_list_item_1, но, похоже, оно не позволяет то, что я хочу.
Если возможно, я также хотел бы иметь возможность изменять цвет предметов независимо друг от друга. Таким образом, текст One будет красным, Two blue и т. Д.
main.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">
<TextView android:id="@+id/textHeader"
android:textSize="24px"
android:textColor="#006699"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Empty set"
/>
<TextView
android:id="@+id/status_text"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
main.java
public class sGuide extends ListActivity {
private String[] mBooks = new String[]{ "One", "Two", "Three" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> booksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mBooks);
this.setListAdapter(booksAdapter);
}
@Override
protected void onDestroy() {
super.onDestroy();
//mChecker.onDestroy();
}
}
Редактировать: вот мой новый макет строки. Я хотел бы сделать так, чтобы касание в любом месте строки выделяло его, а не касалось изображения или метки.
<?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" >
<ImageView
android:id="@+id/icon"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="10dp"
android:layout_marginTop="4dp"
android:src="@drawable/icon"
>
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:layout_marginBottom="9dp"
android:text="@+id/label"
android:textSize="22dp" >
</TextView>
</LinearLayout>
Редактировать 2: изменен линейный макет, чтобы заполнить родительский элемент вместо переноса текста. Теперь это работает.