我需要在textview中显示songtitle2.get(i).charAt(0)
。我已经用歌曲名称填充了列表视图,我希望每次歌曲命名第一个字母更改时都放置分隔符。
adapter = new ArrayAdapter<String>(this,R.layout.song,songtitle);
setListAdapter(adapter);
然后我调用此方法来获取分隔符
private void alphebetdividers(ArrayList<String> songtitle2) {
// TODO Auto-generated method stub
dividerss = (TextView)findViewById(R.layout.song);
int i = 0;
int j = 0;
while( j < songtitle.size()-1){
if(songtitle2.get(i).charAt(0) == songtitle2.get(i+1).charAt(0)){
Toast.makeText(getApplication(), songtitle2.get(i).charAt(0) + "== " + songtitle2.get(i+1).charAt(0), Toast.LENGTH_LONG).show();
}else{
//////DISPLAY CHAR WITH TEXTVIEW//////
}
j++;
i++;
}
}
答案 0 :(得分:3)
只需使用以下内容将char
转换为String
String songName = 'My Song Name'
char my_char = songName.chatAt(0);
String newString = new String(char);
或者只是获取子字符串:
String songName = 'My Song Name'
String newString = songName.subString(0,1);
然后在textview上设置标签:
textView.setText(newString);
答案 1 :(得分:1)
您可以定义类似
char[] ch = { 'a', 'b' };
textView.setText(ch, 0, 2);