我想要实现按一下按钮就加一栏文字
但我以下面的代码按一下按钮都是在同一栏显示
请问如何换行显示啊?
package com.example.xingkongkaohe;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class gongneng extends Activity{
private String result="";
private String shuzhi="";
private int caculate=0;
private ListView lv;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gongneng);
Button button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
EditText edt=(EditText)findViewById(R.id.editText1);
@Override
public void onClick(View V) {
// TODO Auto-generated method stub
String zh=edt.getText().toString();
//public static String result="";
//int caculate=0;
if (zh!="") {
for(int i=0;i<zh.length();i++) //利用for循环逐个提取分析字符串!
{
char word = zh.charAt(i);
if (64<word&&word<91) //利用ASCALL判断大写
{
int a=word+32; //大写转小写
char test1=(char) a;
result=result+test1;
//System.out.println(result);
}
if (97<word&&word<122) //判断小写
{
int b=word-32; //小写转大写
char test2=(char) b;
result=result+test2;
//System.out.println(result);
}
if (48<word&&word<57) //提取数字
{
String test3 = String.valueOf(word);
int c=Integer.parseInt(test3);
caculate=caculate+c; //提取数字进行运算
shuzhi=String.valueOf(caculate);
if (Character.isDigit(zh.charAt(i))) // 向result中加入数字
{
result = result + Integer.parseInt(zh.charAt(i) + "");
}
}
}
//下面是listview代码 关键!
Toast.makeText(gongneng.this, result, Toast.LENGTH_SHORT).show();
ListView lv=(ListView)findViewById(R.id.lv);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(gongneng.this, android.R.layout.simple_expandable_list_item_1,getDate());
lv.setAdapter(adapter);
//*********此处无法动态换行!
}
}
});
}
private String[] getDate() {
return new String[] {result+"\n"+shuzhi};
}
}