问题描述
- Android下,ListView下面的TextView包含超链接点击报错,求高人解决下,谢谢
-
Listview 下面的TextView包含了超链接,点击之后报错,
源码是:
TextView tv_1=(TextView) view.findViewById(R.id.txt_ask);tv_1.setText(Html.fromHtml(str[position])); tv_1.setMovementMethod(LinkMovementMethod.getInstance()); 错误是: 06-15 13:03:47.648: E/InputEventReceiver(30313): Exception dispatching input event.
06-15 13:03:47.648: E/MessageQueue-JNI(30313): Exception in MessageQueue callback: handleReceiveCallback
06-15 13:03:47.655: E/MessageQueue-JNI(30313): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.app.ContextImpl.startActivity(ContextImpl.java:1055)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.app.ContextImpl.startActivity(ContextImpl.java:1042)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.text.style.URLSpan.onClick(URLSpan.java:99)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.widget.TextView.onTouchEvent(TextView.java:7609)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.View.dispatchTouchEvent(View.java:7352)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2075)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1524)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.app.Activity.dispatchTouchEvent(Activity.java:2530)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2023)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.View.dispatchPointerEvent(View.java:7532)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3610)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4862)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4822)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4974)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.os.MessageQueue.nativePollOnce(Native Method)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.os.MessageQueue.next(MessageQueue.java:125)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.os.Looper.loop(Looper.java:140)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at android.app.ActivityThread.main(ActivityThread.java:5383)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at java.lang.reflect.Method.invoke(Method.java:511)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
06-15 13:03:47.655: E/MessageQueue-JNI(30313): at dalvik.system.NativeStart.main(Native Method)
06-15 13:03:47.660: E/AndroidRuntime(30313): FATAL EXCEPTION: main
06-15 13:03:47.660: E/AndroidRuntime(30313): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.app.ContextImpl.startActivity(ContextImpl.java:1055)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.app.ContextImpl.startActivity(ContextImpl.java:1042)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.text.style.URLSpan.onClick(URLSpan.java:99)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.widget.TextView.onTouchEvent(TextView.java:7609)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.View.dispatchTouchEvent(View.java:7352)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
06-15 13:03:47.660: E/AndroidRuntime(30313): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
解决方案
看下MessageQueue callback: handleReceiveCallback 这个方法,它出错了
解决方案二:
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
看到这句话没?
你点击跳转的时候intent加上FLAG_ACTIVITY_NEW_TASK 这个flag。
解决方案三:
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
这句话不是告诉你了吗? intent跳转的时候开个任务。
解决方案四:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_website"
android:layout_width="wrap_content"
android:autoLink="web"
android:layout_height="wrap_content"/>
public class ListViewActivity extends ActionBarActivity {
private ListView listView;
private List<String> list=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_list_view);
listView=(ListView)findViewById(R.id.listview);
initData();
listView.setAdapter(new MyAdapter());
}
private void initData(){
list.add("http://www.hao123.com");
list.add("http://www.sina.com");
}
private class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView=null;
if(convertView==null){
convertView=getLayoutInflater().inflate(R.layout.list_item, parent, false);
textView=(TextView) convertView.findViewById(R.id.tv_website);
}
//textView.setText(getItem(position).toString());
textView.setText(Html.fromHtml(getItem(position).toString()));
return convertView;
}
}
}