显示传递给 listview 的列表并将所选项目的 id 返回给上一个活动

发布于 2024-11-27 01:28:12 字数 225 浏览 1 评论 0原文

我对 Android 开发相当陌生,我想制作一个简单的笔记应用程序作为学习练习。

我有一个带有编辑文本和菜单的活动。单击菜单时,我想显示第二个活动(或类似的活动),让用户选择一个注释,然后将其返回到要编辑的编辑文本。

到目前为止,我能找到的所有教程都使用硬编码列表或资源文件中的列表,我的教程必须更加动态。

非常感谢所有帮助,因为我想编码!

干杯,

威尔。

I am fairly new to Android development, and I would like to make a simple note-taking app as a learning exercise.

I have an activity with an edittext and a menu. when the menu is clicked I would like to display a second activity (or similar) that lets the user select a note that then is returned to the edittext to be edited.

So far all the tutorials I can find use a hard-coded list or a list in a resources file, mine has to be more dynamic.

All help is greatly appreciated as I want to get coding!

Cheers,

Will.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挖鼻大婶 2024-12-04 01:28:12

我不会给你完整的代码,因为你正在学习你应该自己探索它,但我想给你一些提示。

从第一个 Activity 开始,您应该使用 startActivityForResult 启动第二个 Activity,该 Activity 会启动一个 Activity,并且启动的 Activity 将返回一些结果到您的第一个活动。

您可以使用的另一件事是 PutExtra 它可用于传递一些数据活动到另一个。

I won't give you complete code as you are learning you should explore it yourself but I would like to give you some hints.

From your first Activity your should start second activity using startActivityForResult which starts an activity and that started activity will return some results to your first activity.

Another thing you can use is PutExtra which can be used for passing some data from one activity to another.

请止步禁区 2024-12-04 01:28:12

我会给你一个虚拟的方法

创建一个类 theApp

public class theApp extends Application {
private String Note;

public String getNote(){
    return Note;
    }
public void setNote(String Note){
    this.Note = Note;
    }
}

在清单中

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:name="theApp">

(更改 android:name="theApp")在第一个活动中(返回到第二个活动):

            Intent myIntent = new Intent(FIRSTACTIVITY.this,CALLED_ACTIVITY.class);
            Bundle bundle = new Bundle();
            bundle.putString("key1", whatever);//if you want to send some string
            bundle.putString("key2", whatever);//you can also send integers and others using putInt and others
            myIntent.putExtras(bundle);
            startActivityForResult(myIntent, 0);

在第二个活动中(返回第一个活动):

            ((theApp)getApplicationContext()).setNote(a_STRING);
            setResult(ANY_INTEGER);
            finish();

最后在第一个活动中

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // use ((theApp)getApplicationContext()).getNote();
    // if you want you can use ANY_INTEGER (which was set in the second activity using setResult
    // Access ANY_INTEGER using resultCode
}

I will give you a dummy way

Create a class theApp

public class theApp extends Application {
private String Note;

public String getNote(){
    return Note;
    }
public void setNote(String Note){
    this.Note = Note;
    }
}

In the manifest (change the android:name="theApp")

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:name="theApp">

In the first activity (to return to the second activity):

            Intent myIntent = new Intent(FIRSTACTIVITY.this,CALLED_ACTIVITY.class);
            Bundle bundle = new Bundle();
            bundle.putString("key1", whatever);//if you want to send some string
            bundle.putString("key2", whatever);//you can also send integers and others using putInt and others
            myIntent.putExtras(bundle);
            startActivityForResult(myIntent, 0);

In the second activity (to return to the first activity):

            ((theApp)getApplicationContext()).setNote(a_STRING);
            setResult(ANY_INTEGER);
            finish();

Finally in the first activity

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // use ((theApp)getApplicationContext()).getNote();
    // if you want you can use ANY_INTEGER (which was set in the second activity using setResult
    // Access ANY_INTEGER using resultCode
}
为人所爱 2024-12-04 01:28:12

我认为JavaNut13更关心他的列表中的视图而不是活动。

@JavaNut13,看看 http://thinkandroid.wordpress.com/2010 /01/13/自定义基础适配器/

I think JavaNut13 is more concerned about the views in his list and not activities.

@JavaNut13, take a look at http://thinkandroid.wordpress.com/2010/01/13/custom-baseadapters/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文