我正在生成一个ListView使用SimpleAdapter.我的SimpleAdapter代码如下:
ListAdapter k = new SimpleAdapter(this, val1, R.layout.mytask, new String[]{"TaskId", "heading", "status"}, new int[]{R.id.View1, R.id.View2, R.id.ViewStatus});
Run Code Online (Sandbox Code Playgroud)
我的活动是MainActivity哪个extends Activity.我想要override这个getview()方法.我怎样才能做到这一点?
我是android的新手,我有一个问题.我正在使用带有ViewBender的SimpleAdapter来显示图像和文本.但是我无法弄清楚如何为SimpleAdapter设置OnItemClickListener.我该怎么做?这是我初始化它的方式:
SimpleAdapter notes = new SimpleAdapter(Main.this, list, R.layout.main_list_row, PARAM, new int[] { R.id.icon, R.id.name, R.id.content });
notes.setViewBinder(new MyViewBinder());
setListAdapter(notes);
Run Code Online (Sandbox Code Playgroud)
提前致谢
我有listView和SimpleAdapter,它设置我的listView.但setOnItemClickListener事件没有提出.
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.add_item_from_subcateg);
subcategName = getIntent().getExtras().getString("subcategName");
mySQLWorker = new MySQLWorker(this);
mySQLWorker.open();
list_view_products = (ListView) findViewById(android.R.id.list);
finishLoading(null);
}
public void finishLoading(ArrayList<HashMap<String, Object>> result)
{
HashMap<String, Object> hashmap;
List<ProductInfo> products = mySQLWorker.GetProductsByCategory(subcategName);
for (ProductInfo product : products)
{
hashmap = new HashMap<String, Object>();
hashmap.put("ItemID", product.getID());
hashmap.put("image_product", product.getImagePath());
hashmap.put("product_name", product.getName());
hashmap.put("lbl_protein_count", product.getProtein());
hashmap.put("lbl_fat_count", product.getFat());
hashmap.put("lbl_carbohydrates_count", product.getCarbohydrates());
list_products.add(hashmap);
}
adapterProductsList = new SimpleAdapter(mContext, list_products,
R.layout.product_template, new String[] …Run Code Online (Sandbox Code Playgroud) 我是Android的新手.我也提前发布了这个问题,但没有找到合适的答案.我的要求是做一个Button可点击的Listview,其使用产生的SimpleAdapter.我不想使用CustomAdapter,BaseAdapter或任何其他适配器.我不想将我的Activty扩展为.SimpleAdapter我的代码和错误日志如下.如果有人有任何解决方案,请一步一步向我解释.谢谢.
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<HashMap<String, String>>val1=new ArrayList<HashMap<String,String>>();
HashMap<String, String>val=new HashMap<String,String>();
val.put("a","a");
val.put("c","c");
val.put("b","b");
val1.add(val);
final ListView l=(ListView)findViewById(R.id.listView1);
ListAdapter k=new SimpleAdapter(this,val1,R.layout.mytask,new String[]{"TaskId","heading","status"},new int[]{R.id.View1,R.id.View2,R.id.ViewStatus});
Button b=(Button)findViewById(R.id.mytask);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,"save",Toast.LENGTH_SHORT).show();
}
});
l.setAdapter(k);
}
Run Code Online (Sandbox Code Playgroud)
错误日志:
04-07 01:43:07.075: E/AndroidRuntime(2113): FATAL EXCEPTION: main
04-07 01:43:07.075: E/AndroidRuntime(2113): Process: com.example.s, PID: …Run Code Online (Sandbox Code Playgroud) 帮助从ArrayList获取值
data = new ArrayList<Map<String, String>>();
for (int i = 0; i < marks.length; i++) {
HashMap<String, String> m = new HashMap<String, String>();
m.put("title", marks[i].getUserName());
m.put("mark", marks[i].getMark().toString());
m.put("type", marks[i].getType().toString());
m.put("description", marks[i].getDescription());
data.add(m);
}
Run Code Online (Sandbox Code Playgroud)
试图从适配器中取出一个ArrayList并将值写入数组:
data = simpleAdapter.getData();
MarksRead[] marksReads = new MarksRead[data.size()];
for (int i = 0; i < data.size(); i++) {
marksReads[i].setDescription(data(i).get("description"));
marksReads[i].setMark(Integer.valueOf(data.get(i).get("mark")));
marksReads[i].setType(Integer.valueOf(data.get(i).get("type")));
}
Run Code Online (Sandbox Code Playgroud)
在线marksReads[i].setDescription(data(i).get("description"));输出是Exception NullPointerException.
帮忙,怎么做对.