0

ok, so this is my first project on my own, i'm supposed to be done in 2 weeks. i am doing it with android studio. but now i got stuck when i am trying to make a button work. what am i doing wrong? i have been on google for a few hours, but my english are not as good as i thought, and i can't seem to fin the right words to google.

i am also having problem with my textfield, it is just on row, and it will continue towards right forever, without any possibility to begin on a new line.

sorry for mixing languages annteckningsblock=NotePad

questions:

  1. (solved) why does my button not work? it say something about a constructor

  2. (solved) how do i make my textfield to make more than one line

  3. my app crasches when i press "Go Back" do i have to write anything in the other class? i am really bad at this.

  4. i am trying to press th "go back" button, but than the app crasches and i get this error: have you declared this activity in your AndroidManifest.xml? what have i done wrong?

the code:

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.felix.anteckningsblock" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".anteckningsblock"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

anteckningsblock.java

package se.felix.anteckningsblock;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.app.Activity;


public class anteckningsblock extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_anteckningsblock);

    Button button = (Button)findViewById(R.id.GoBack);
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(v.getContext(), Notelist.class);
            v.getContext().startActivity(i);
        }
    });
}
}

notelist.java:

package se.felix.anteckningsblock;

import android.app.ListActivity;
import android.os.Bundle;


public class Notelist extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notelist);
    }
}

activity_anteckningsblock.xml

<RelativeLayout 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"
    tools:context=".anteckningsblock"
    android:background="@color/Blue">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/knappar"
        android:layout_marginRight="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">


    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="@string/Save"
        android:id="@+id/SaveButton"
        android:layout_alignParentLeft="true" />

    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="@string/Delete"
        android:id="@+id/DeleteButton"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="@string/Back"
        android:id="@+id/GoBack"
        android:layout_centerHorizontal="true"
        android:onClick="start" />

    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/knappar"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/TextField"
        android:background="@color/Green"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp">

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:id="@+id/EditText"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:textColor="@color/Yellow"
            android:inputType="textMultiLine"
            android:verticalScrollbarPosition="right"/>
        </RelativeLayout>

</RelativeLayout>

notelist.xml

<RelativeLayout 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"
    tools:context=".anteckningsblock"
    android:background="@color/Blue">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Note"
        android:id="@+id/New"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <ListView
        android:id="@+id/NoteList"
        android:layout_above="@id/New"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />


</RelativeLayout>
  • possible duplicate of [Allow multi-line in EditText view in Android?](http://stackoverflow.com/questions/4233626/allow-multi-line-in-edittext-view-in-android) – Kuba Spatny Jan 09 '15 at 14:29

1 Answers1

0

You can't pass this to your Intent in the OnClickListener, because this references the OnClickListener and not your Activity and its Context.

Instead do something like:

Button button = (Button)findViewById(R.id.GoBack);
button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Intent i = new Intent(v.getContext(), Notelist.class);
        v.getContext().startActivity(i);
    }
});

Regarding your EditText:

     <EditText
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:inputType="textMultiLine" <!-- Should include multiple lines and line break -->
        android:id="@+id/EditText"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textColor="@color/Yellow"
        android:inputType="textCapSentences"
        android:verticalScrollbarPosition="right"/>
Ca11e
  • 103
  • 9