首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >试着做一个与iphone上的记事本非常相似的笔记本

试着做一个与iphone上的记事本非常相似的笔记本
EN

Stack Overflow用户
提问于 2015-01-09 14:25:20
回答 1查看 300关注 0票数 0

好的,这是我自己的第一个项目,我应该在两周内完成。我是用android工作室做的。但是现在当我想让一个按钮工作时,我被卡住了。我做错什么了?我在谷歌上已经有几个小时了,但我的英语不如我想象的那么好,而且我似乎找不到合适的词给谷歌。

我的textfield也有问题,它只是排在行上,而且它将永远向右移动,没有任何可能从新的行开始。

不好意思混合语言annteckningsblock=NotePad

问题:

  1. (解决了)为什么我的按钮不工作?它说明了一个构造函数
  2. (解决了)如何使我的文本字段生成多行
  3. 当我按下“回去”键时,我的应用程序就会崩溃--我必须在另一堂课上写什么吗?我在这方面真的很差。
  4. 我正试图按下“返回”按钮,但比应用程序崩溃时,我得到了一个错误:您在AndroidManifest.xml中声明了这个活动吗?我做错了什么?

守则:

manifest.xml

代码语言:javascript
运行
复制
<?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

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
<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

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-09 14:36:56

您不能在OnClickListener中将其传递给您的意图,因为它引用的是OnClickListener,而不是您的活动及其上下文。

相反,你可以做如下的事情:

代码语言:javascript
运行
复制
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);
    }
});

关于您的EditText:

代码语言:javascript
运行
复制
     <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"/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27862708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档