我现在 做一个作业 做一个英语的单词本 我现在在里面添加了3天数据 分别是 id english chinese这个格式的 就是 用listview显示出来 比如 : 1 dog 狗 我现在做到了private void query() {
Cursor cursor=getContentResolver().query(DBhelper.word.CONTENT_URI, new String[]{ DBhelper.word._ID,
DBhelper.word.WORD_ENGLISH,
DBhelper.word.WORD_CHINA }, null, null, null);
if(cursor.moveToNext()){
do {
String ID=null;
ID=cursor.getString(cursor.getColumnIndex(DBhelper.word._ID));
String english=null;
english=cursor.getString(cursor.getColumnIndex(DBhelper.word.WORD_ENGLISH));
String chinese=null;
chinese=cursor.getString(cursor.getColumnIndex(DBhelper.word.WORD_CHINA));
Log.e("打印出ID", ID);
Log.e("打印出英语的", english);
Log.e("打印出中文的", chinese);
} while (cursor.moveToNext());
};这一步 之后我写
SimpleAdapter adapter=new SimpleAdapter(this, list, R.layout.view, new String[]{"word_english","word_china"}, new int[]{R.id.b,R.id.c});这步时候 SimpleAdapter的第二个参数需要一个 List<? extends Map<String, ?>>这个形式的 我不知道该怎么办了
在log中 所有的数据都能显示出来 我就是不知道怎么放进去 求大神 给分!!!
Cursor cursor=getContentResolver().query(DBhelper.word.CONTENT_URI, new String[]{ DBhelper.word._ID,
DBhelper.word.WORD_ENGLISH,
DBhelper.word.WORD_CHINA }, null, null, null);
if(cursor.moveToNext()){
do {
String ID=null;
ID=cursor.getString(cursor.getColumnIndex(DBhelper.word._ID));
String english=null;
english=cursor.getString(cursor.getColumnIndex(DBhelper.word.WORD_ENGLISH));
String chinese=null;
chinese=cursor.getString(cursor.getColumnIndex(DBhelper.word.WORD_CHINA));
Log.e("打印出ID", ID);
Log.e("打印出英语的", english);
Log.e("打印出中文的", chinese);
} while (cursor.moveToNext());
};这一步 之后我写
SimpleAdapter adapter=new SimpleAdapter(this, list, R.layout.view, new String[]{"word_english","word_china"}, new int[]{R.id.b,R.id.c});这步时候 SimpleAdapter的第二个参数需要一个 List<? extends Map<String, ?>>这个形式的 我不知道该怎么办了
在log中 所有的数据都能显示出来 我就是不知道怎么放进去 求大神 给分!!!
Map<String, String> map = new HashMap<String, String>();
map.put("nick","张三");
map.put("origtext","张三发了一条微博,哈哈");
data.add(map);
Map<String, String> map2 = new HashMap<String, String>();
map2.put("nick","李四");
map2.put("origtext", "李四发了一条微博,哈哈");
data.add(map2);
SimpleAdapter adapter=new SimpleAdapter(
this,
data, //数据
R.layout.listview, //listview的布局文件
new String[]{"nick","origtext"}, //填充的数据的key
new int[]{R.id.tv_nick,R.id.tv_origtext} //填充对象的id
);
listView.setAdapter(adapter);
map.put("nick","张三");
map.put("origtext","张三发了一条微博,哈哈");
map.put("nick","张三");
map.put("origtext","张三发了一条微博,哈哈");
这其中的张三 跟 张三发了一条微博,哈哈 我对应的内容都找到了 怎样让他动态的显示
这里举例这样写的,你对应的数据存到map中就好了啊在难点的话,就要自定义adapter,这样填充数据也方便
我的代码是这样的public class Two extends Activity {
String ID=null;
String english=null;
String chinese=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
query();
} private void query() {
Cursor cursor=getContentResolver().query(DBhelper.word.CONTENT_URI, new String[]{ DBhelper.word._ID,
DBhelper.word.WORD_ENGLISH,
DBhelper.word.WORD_CHINA }, null, null, null);
if(cursor.moveToNext()){
do {
ID=cursor.getString(cursor.getColumnIndex(DBhelper.word._ID));
english=cursor.getString(cursor.getColumnIndex(DBhelper.word.WORD_ENGLISH));
chinese=cursor.getString(cursor.getColumnIndex(DBhelper.word.WORD_CHINA));
Log.e("打印出ID", ID);
Log.e("打印出英语的", english);
Log.e("打印出中文的", chinese);
} while (cursor.moveToNext());
};
SimpleAdapter adapter=new SimpleAdapter(this,getData(), R.layout.view,
new String[]{"_id","word_english","word_china"},
new int[]{R.id.id,R.id.english,R.id.chinese});
} private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("_id", _id);
map.put("word_english",english);
map.put("word_china", chinese);
list.add(map);
return list;
在手机上 数据都不显示 log表示有了数据
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/chinese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>