ArrayAdapter <HashMap > with commonsguy EndlessAdapter类

如何使用ArrayAdapter-HashMap-与EndlessAdapter类?

class DemoAdapter extends EndlessAdapter { private RotateAnimation rotate=null; @SuppressWarnings("unchecked") ArrayAdapter<HashMap> a=(ArrayAdapter<HashMap>)getWrappedAdapter(); DemoAdapter(ArrayList<HashMap> items) { super(new ArrayAdapter<HashMap>(Base.this, R.layout.row, android.R.id.text1, <------ ???? items)); <------ ???? 

我的行R.layout.text1和R.layout.text2中有两列。

我看到PROJECTION_COLUMNSVIEW_MAPPINGS几个例子,但不知道如何正确使用它。

这是完整的代码,它正在工作,但我在Listview(text1)中得到类似{test2 = dasdasd,test1 = asdasd}的内容:

 import com.commonsware.cwac.endless.EndlessAdapter; import java.util.ArrayList; import java.util.HashMap; public class Read extends ListActivity { EndlessAdapter x; SQLiteDatabase Db; public Cursor c; Integer cx; String Hash; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.readmain); Hash = getIntent().getStringExtra("Hash"); cx = getIntent().getIntExtra("Count", 0); Db = openOrCreateDatabase("/sdcard/test.db", SQLiteDatabase.CREATE_IF_NECESSARY, null); ArrayList<HashMap> items=new ArrayList<HashMap>(); x = new DemoAdapter(items); setListAdapter(x); } class DemoAdapter extends EndlessAdapter { private RotateAnimation rotate=null; @SuppressWarnings("unchecked") ArrayAdapter<HashMap> a=(ArrayAdapter<HashMap>)getWrappedAdapter(); DemoAdapter(ArrayList<HashMap> items) { super(new ArrayAdapter<HashMap>(ReadChat.this, R.layout.row, R.id.textas1, items)); rotate=new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(600); rotate.setRepeatMode(Animation.RESTART); rotate.setRepeatCount(Animation.INFINITE); } @Override protected View getPendingView(ViewGroup parent) { View row=getLayoutInflater().inflate(R.layout.row, null); View child=row.findViewById(R.id.textas1); child.setVisibility(View.GONE); child=row.findViewById(R.id.throbber); child.setVisibility(View.VISIBLE); child.startAnimation(rotate); return(row); } @Override protected boolean cacheInBackground() { c = Db.rawQuery("SELECT a, b FROM TableLIMIT "+a.getCount()+", 15",null); return(getWrappedAdapter().getCount()< cx); } @Override protected void appendCachedData() { String a; String b; if (c != null ) { if (c.moveToFirst()) { do { a = c.getString(c.getColumnIndex("a")); b = c.getString(c.getColumnIndex("b")); HashMap temp = new HashMap(); temp.put("test1", a); temp.put("test2", b); a.add(temp); } while (c.moveToNext()); } } } } } 

你的问题与EndlessAdapter

首先,让你的代码使用ArrayAdapterEndlessAdapter忽略EndlessAdapter 。 这将要求您学习如何创建自定义ArrayAdapter ,因为您将很快发现ArrayAdapter对如何使用HashMap知之甚少。 您需要将ArrayAdapter扩展到您自己的WhateverThisIsAdapter ,您可以在其中覆盖getView()以处理从HashMap将数据倾注到膨胀的行中,从而正确处理行回收。 我的一本书的 免费摘录将展示其中的一些内容。

然后,只有这样,将工作的ArrayAdapter包装在EndlessAdapter

此外,从来没有硬线路径,因为/sdcard在大多数Android设备上都是错误的。