android获取edittext内容出错,从edittext获取字符串android是错误

我是初学者的android。我有问题要从编辑视图中获取文本字符串。请帮我修复它。非常感谢。 CommentActivity.java从edittext获取字符串android是错误

public class CommentActivity extends Fragment {

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

}

TextView cmt;

ArrayAdapter adapter;

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.comment_layout, container, false);

Button send = (Button) v.findViewById(R.id.send_comment);

cmt = (TextView) v.findViewById(R.id.text_comment);

ListView lst = (ListView) v.findViewById(R.id.list_comments);

String[] values = new String[] {};

adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values);

lst.setAdapter(adapter);

send.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v)

{

CharSequence content = cmt.getText();

cmt.setText("");

adapter.add((String) content);

adapter.notifyDataSetChanged();

Toast.makeText(getActivity(), content, Toast.LENGTH_SHORT).show();

}

});

return v;

}

}

其错误:

12-11 16:39:10.244: E/PlayerDetailActivity(25813): Uncaught exception

12-11 16:39:10.244: E/PlayerDetailActivity(25813): java.lang.ClassCastException: android.text.SpannableStringBuilder

cannot be cast to java.lang.String

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at RanhTV.Controller.CommentActivity$1.onClick(CommentActivity.java:36)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at android.view.View.performClick(View.java:4424)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at android.view.View$PerformClick.run(View.java:18383)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at android.os.Handler.handleCallback(Handler.java:733)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at android.os.Handler.dispatchMessage(Handler.java:95)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at android.os.Looper.loop(Looper.java:137)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at android.app.ActivityThread.main(ActivityThread.java:4998)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at java.lang.reflect.Method.invokeNative(Native Method)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at java.lang.reflect.Method.invoke(Method.java:515)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)

12-11 16:39:10.244: E/PlayerDetailActivity(25813): at dalvik.system.NativeStart.main(Native Method)

+0

代替铸造用toString方法在数组列表中添加字符串:'adapter.add(content.toString() );' –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值