我写了一个SimpleAdapter+ListView显示数据,但页面就是没有显示出数据,求高手帮忙解决,急 急 急!!!
super.onCreate(savedInstanceState);setContentView(R.layout.news_activity);List<Map<St...
super.onCreate(savedInstanceState);
setContentView(R.layout.news_activity);
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
int size = getResources().getStringArray(R.array.news_title).length;
ListView listView = (ListView)findViewById(R.id.newsListView);
Map<String, Object> map = new HashMap<String, Object>();
for (int i=0; i<size; i++){
map.put("title", R.array.news_title);
map.put("content", R.array.news_Content);
list.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(NewsActivity.this, list,R.layout.news_activity_item, new String[]{"title", "content"}, new int[]{R.id.txtTitle, R.id.txtContent});
listView.setAdapter(adapter);
这是onCreate方法里的代码 高手帮小弟解决下吧 急啊 纠结了2天了
这是news_activity页面
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/newsListView" android:divider="#ffcccccc" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
这是news_activity_item页面
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/txtTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/Fanski.BlueNormalText" />
<TextView android:id="@+id/txtContent" android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/Fanski.BlackNormalText" />
</LinearLayout> 展开
setContentView(R.layout.news_activity);
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
int size = getResources().getStringArray(R.array.news_title).length;
ListView listView = (ListView)findViewById(R.id.newsListView);
Map<String, Object> map = new HashMap<String, Object>();
for (int i=0; i<size; i++){
map.put("title", R.array.news_title);
map.put("content", R.array.news_Content);
list.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(NewsActivity.this, list,R.layout.news_activity_item, new String[]{"title", "content"}, new int[]{R.id.txtTitle, R.id.txtContent});
listView.setAdapter(adapter);
这是onCreate方法里的代码 高手帮小弟解决下吧 急啊 纠结了2天了
这是news_activity页面
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/newsListView" android:divider="#ffcccccc" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
这是news_activity_item页面
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/txtTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/Fanski.BlueNormalText" />
<TextView android:id="@+id/txtContent" android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/Fanski.BlackNormalText" />
</LinearLayout> 展开
1个回答
展开全部
感觉这个不太对:SimpleAdapter adapter = new SimpleAdapter(NewsActivity.this, list,R.layout.news_activity_item, new String[]{"title", "content"}, new int[]{R.id.txtTitle, R.id.txtContent});
把R.layout.news_activit_item换成系统的试试:android.R.layout.simple……(具体是啥忘了)
把R.layout.news_activit_item换成系统的试试:android.R.layout.simple……(具体是啥忘了)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询