newbie here to android/java code... fully expect downvotes. but hopefully some other dude will be able to easily find this and not have to ask what the problem is.
Trying to get a button when clicked to send user to an external website
public class MessagesFragment extends Fragment {
public MessagesFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("http://www.stackoverflow.com/"));
startActivity(viewIntent);
}
});
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_messages, container, false);
}
}
Button,(Button)findViewById, setOnClickListener, OnClickListener(), Intent, Intent, Uri. all have errors -_-
Here is the xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#67ffae"
tools:context=".MessagesFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:text="Messages Fragment" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>
lalalalalalalalalalalalalalalalalalalalala I know its mostly code that's what we are discussing stack overflow.