导航栏模拟器显示正常,真机显示乱码,求教! 乱码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建议用String.xml不要自己去写,,, 你在UTF-8下面写文本,把项目都统一成一个字符编码,注意全角半角。 我把有关导航栏的代码都粘出来,帮忙会诊一下:1、导航栏数组文件:arrays.xml<?xml version="1.0" encoding="utf-8"?><resources> <string-array name="categories"> <item>1|焦点</item> <item>2|国内</item> <item>3|国际</item> <item>4|军事</item> <item>5|体育</item> <item>6|科技</item> <item>7|汽车</item> <item>8|财经</item> <item>9|游戏</item> <item>10|女人</item> </string-array></resources>2、导航栏绑定代码//获取新闻分类 String[] categoryArray = getResources().getStringArray(R.array.categories); //把新闻分类保存到List中 final List<HashMap<String, Category>> categories = new ArrayList<HashMap<String, Category>>(); //分割新闻类型字符串 for(int i=0;i<categoryArray.length;i++) { String[] temp = categoryArray[i].split("[|]"); if (temp.length==2) { int cid = StringUtil.String2Int(temp[0]); String title = temp[1]; Category type = new Category(cid, title); HashMap<String, Category> hashMap = new HashMap<String, Category>(); hashMap.put("category_title", type); categories.add(hashMap); } } //默认选中的新闻分类 mCid = 1; //创建Adapter,指明映射字段 CustomSimpleAdapter categoryAdapter = new CustomSimpleAdapter(this, categories, R.layout.category_title, new String[]{"category_title"}, new int[]{R.id.category_title}); GridView category = new GridView(this); category.setColumnWidth(mColumnWidthDip);//每个单元格宽度 category.setNumColumns(GridView.AUTO_FIT);//单元格数目 category.setGravity(Gravity.CENTER);//设置对其方式 //设置单元格选择是背景色为透明,这样选择时就不现实黄色北京 category.setSelector(new ColorDrawable(Color.TRANSPARENT)); //根据单元格宽度和数目计算总宽度 int width = mColumnWidthDip * categories.size(); LayoutParams params = new LayoutParams(width, LayoutParams.FILL_PARENT); //更新category宽度和高度,这样category在一行显示 category.setLayoutParams(params); //设置适配器 category.setAdapter(categoryAdapter); //把category加入到容器中 LinearLayout categoryList = (LinearLayout) findViewById(R.id.category_layout); categoryList.addView(category); //添加单元格点击事件 关于apk在桌面显示的问题,请帮帮忙 Android-x86入门之--固化启动参数 自动发彩信 android源码 用http方式,根据经纬度查地址出错 android 不可以自己创建资源目录吗? TabHost中给Indicator添加click事件,首次被截取! json解析 Android客户端通过TCP向网络发送信息 关于Android手机和wear通信的问题 AlertDialog添加垂直滚动条 android 4.0 应用软件如何查找、读写USB,HID设备?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="categories">
<item>1|焦点</item>
<item>2|国内</item>
<item>3|国际</item>
<item>4|军事</item>
<item>5|体育</item>
<item>6|科技</item>
<item>7|汽车</item>
<item>8|财经</item>
<item>9|游戏</item>
<item>10|女人</item>
</string-array>
</resources>
2、导航栏绑定代码
//获取新闻分类
String[] categoryArray = getResources().getStringArray(R.array.categories);
//把新闻分类保存到List中
final List<HashMap<String, Category>> categories = new ArrayList<HashMap<String, Category>>();
//分割新闻类型字符串
for(int i=0;i<categoryArray.length;i++)
{
String[] temp = categoryArray[i].split("[|]");
if (temp.length==2)
{
int cid = StringUtil.String2Int(temp[0]);
String title = temp[1];
Category type = new Category(cid, title);
HashMap<String, Category> hashMap = new HashMap<String, Category>();
hashMap.put("category_title", type);
categories.add(hashMap);
}
}
//默认选中的新闻分类
mCid = 1;
//创建Adapter,指明映射字段
CustomSimpleAdapter categoryAdapter = new CustomSimpleAdapter(this, categories, R.layout.category_title, new String[]{"category_title"}, new int[]{R.id.category_title});
GridView category = new GridView(this);
category.setColumnWidth(mColumnWidthDip);//每个单元格宽度
category.setNumColumns(GridView.AUTO_FIT);//单元格数目
category.setGravity(Gravity.CENTER);//设置对其方式
//设置单元格选择是背景色为透明,这样选择时就不现实黄色北京
category.setSelector(new ColorDrawable(Color.TRANSPARENT));
//根据单元格宽度和数目计算总宽度
int width = mColumnWidthDip * categories.size();
LayoutParams params = new LayoutParams(width, LayoutParams.FILL_PARENT);
//更新category宽度和高度,这样category在一行显示
category.setLayoutParams(params);
//设置适配器
category.setAdapter(categoryAdapter);
//把category加入到容器中
LinearLayout categoryList = (LinearLayout) findViewById(R.id.category_layout);
categoryList.addView(category);
//添加单元格点击事件