如上所述,您需要擴展適配器並將其用於ListActivity。使用TextView和ImageView製作XML文件(使用LinearLayout或任何其他佈局)。您可以將ID添加到TextView和ImageView,以便可以根據列表中的位置更改它們。
這是一個代碼示例,它創建三行並將它們中的文本設置爲a,b,c。
public class MyActivity extends ListActivity {
private String[] data = {"a","b","c"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MyAdapter(this, R.layout.rowxml, data));
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context c, int i, String[] s) {
super(c, i, s);
}
@Override
public View getView(int position, View v, ViewGroup parent) {
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.rowxml, null);
}
TextView tw = (TextView) v.findViewById(R.id.text);
if (tw != null) tw.setText(data[position]);
// You can do something similar with the ImageView
return v;
}
}
}
[Android Developer Resources](http://developer.android.com/resources/index.html) –