我正在使用LinearLayout来显示一些文本和图像。我有可绘制/的图像,我用ListActivity和一些onListItemClick功能来实现这一点。现在我想更改由onclick功能处理的行的图像,以显示处理后的状态。有人可以帮助我解决这个问题,在运行时改变图像。在运行时在ListView上更改图像android
以下是我的实践。
public class ListWithImage extends ListActivity {0}当调用第一次创建时调用。 */
private SimpleCursorAdapter myAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// raj setContentView(R.layout.main);
Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(cursor);
String[] columns = new String[] {People.NAME, People.NUMBER};
int[] names = new int[] {R.id.contact_name, R.id.contact_number};
myAdapter = new SimpleCursorAdapter(this, R.layout.main, cursor, columns, names);
setListAdapter(myAdapter);
}
@Override
protected void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
Intent intent = new Intent(Intent.ACTION_CALL);
Cursor cursor = (Cursor) myAdapter.getItem(position);
long phoneId = cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID));
intent.setData(ContentUris.withAppendedId(Phones.CONTENT_URI, phoneId));
startActivity(intent);
}
}
和main.xml中是:
<LinearLayout
android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="250px">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: " />
<TextView android:id="@+id/contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone: " />
<TextView android:id="@+id/contact_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
我认为添加字段为DB。但我无法知道如何用代码更改图像。任何人都可以为我提供一个用代码绘制图像的示例,并根据运行时的条件对其进行更改。
我想把这个字段添加到数据库中。 但我无法知道如何用代码更改图像。 任何人都可以为我提供这个问题的例子,如果知道。 – Raj 2010-06-04 06:13:45
这并不难。你需要在代码中保存图像视图(比如'ImageView iv = findViewById(R.id.image_view_id); iv.setImage ...'我写了...因为你可以通过设置图像使用资源,位图+++和方法名称是不同的。 – Alxandr 2010-06-04 10:49:59