将图像动态添加到android listView项
我正在尝试向将图像动态添加到android listView项,android,listview,imageview,Android,Listview,Imageview,我正在尝试向列表视图行动态添加图像。我必须创建一个自定义光标还是什么?我只是不知道把代码放在哪里来更改图像源 谢谢 这是活动 public class ViewPlayersActivity extends Activity { ListView nameList; MySQLiteAdapters adapter_ob; MySQLiteHelper helper_ob; SQLiteDatabase db_ob; Button registerBtn;
列表视图
行动态添加图像。我必须创建一个自定义光标还是什么?我只是不知道把代码放在哪里来更改图像源
谢谢
这是活动
public class ViewPlayersActivity extends Activity {
ListView nameList;
MySQLiteAdapters adapter_ob;
MySQLiteHelper helper_ob;
SQLiteDatabase db_ob;
Button registerBtn;
Cursor cursor, cursor2, cursor3;
String context;
public static final String PREFS = "examplePrefs";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_players);
nameList = (ListView) findViewById(R.id.listView);
adapter_ob = new MySQLiteAdapters(this);
Bundle extras = getIntent().getExtras();
SharedPreferences exmaple = getSharedPreferences(PREFS, 0);
context = exmaple.getString("teamName", "cant find team");
String[] from = {helper_ob.KEY_FNAME, helper_ob.KEY_LNAME};
int[] to = { R.id.tv_fname, R.id.tv_lname};
cursor = adapter_ob.queryName(context);
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
nameList.setAdapter(cursorAdapter);
nameList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Bundle passdata = new Bundle();
Cursor listCursor = (Cursor) arg0.getItemAtPosition(arg2);
int nameId = listCursor.getInt(listCursor
.getColumnIndex("p_id"));
passdata.putInt("keyid", nameId);
Intent passIntent = new Intent(ViewPlayersActivity.this,
EditPlayerActivity.class);
passIntent.putExtras(passdata);
startActivity(passIntent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.view_players, menu);
return true;
}
// method refreshes this view to show record updates & Deletes
public void onResume() {
super.onResume();
cursor.requery();
}
下面是一行的当前xml。我在这里添加了一个静态图像,但我需要它是动态的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listcontainer"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_fname"
android:layout_width="210dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_lname"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:layout_marginLeft="20dp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_center" />
</LinearLayout>
下面是添加几行后ListView的外观
对于动态图像,您应该执行元素自定义
SimpleCursorAdapter
参见示例从何处获取图像?我的意思是来源是什么?@ρц∑ρєK-你的链接断了