问题描述
我使用的LinearLayout显示一些文字和图片。我有张图像绘制/和我与一些onListItemClick功能ListActivity implimenting这一点。现在我想改变图像这是由的onclick功能处理,以显示为处理状态的行。可以有人帮助我在这个问题上在运行时更改图像。
I am using a LinearLayout to display some Text and image. I have the images at drawable/ and i am implimenting this with ListActivity with some onListItemClick functionality. now i wants to change the image for the rows which are processed by onclick functionality to show the status as processed. can some one help me in this issue to change the image at runtime.
以下是我的执行力度。
公共类ListWithImage扩展ListActivity {
/ **当第一次创建活动调用。 * /
public class ListWithImage extends ListActivity { /** Called when the activity is first created. */
私人SimpleCursorAdapter myAdapter;
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中是:
and main.xml is :
<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>
结果
我认为将该字段添加到数据库中。但我无法知道如何与code更改图像。任何一个可以给我一个例子与code绘画图像,并改变它的基础上运行时的条件。
I thought to add the field to DB. but i was unable to know how to change the image with code. can any one provide me an example for drawing image with code and change it based on a condition at runtime.
推荐答案
我已经做了同样的事情在我的应用程序(但我没有使用的CursorAdapter,但自定义适配器,但逻辑应该是相同的)。
I've done the same thing in my application (however I didn't use a cursoradapter but a custom adapter, however the logic should be the same).
我需要得到这个工作将包括在指定惠特与否现场处理(或某些领域的决定显示哪些图片)数据库的字段。然后,你需要绑定你的图像处理该字段。我不知道,如果你能做到这一点的simplecursoradapter,或者如果你需要,虽然实现自己的。
What I needed to get this working was to include a field in the db which specifies wheater or not the field is processed (or some field deciding which image to show). Then you need to bind your images address to that field. I don't know if you can do this with the simplecursoradapter, or if you need to implement your own though.
然后,当用户点击你刚才设置的项目作为DB处理的项目,你告诉你的适配器,它已被更新。
Then, when a user clicks an item you just set that item as processed in the db, and you tell your adapter that it has been updated.
这篇关于在Android的运行上的ListView改变形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!