简体   繁体   English

ListView到New Activity,然后使用Hashmap中的SQLite数据填充EditText

[英]ListView to New Activity then Populate EditText's with SQLite data from Hashmap

I currently have a ListView populated by SQLite and I have implemented an OnItemClickListener to list items. 我目前有一个由SQLite填充的ListView,并且已经实现了一个OnItemClickListener来列出项目。 I want to know how to retrieve values from a Hashmap specific to the item the user clicks in the ListView, then open a new activity and populate the retrieved data into EditTexts. 我想知道如何从Hashmap中检索特定于用户在ListView中单击的项目的值,然后打开一个新活动并将检索到的数据填充到EditTexts中。 Any help would be appreciated! 任何帮助,将不胜感激!

EDIT 编辑

This is what i'm guessing: 这就是我的猜测:

    public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
            ArrayList<HashMap<String, String>> scanList = this.controller.getAllRecs();
            Intent intent = new Intent (parent.getContext(), Record.class);
            intent.putExtra("key", scanList);
        }

Then in my next activity in the onCreate have the following: 然后在onCreate的下一个活动中,有以下内容:

String value = getIntent().getExtras().getString("key");
        ET1.setText(value);

Following the HUGE help in the comments from Filipe (Thanks again) the following is the solution to the problem: 在Filipe的评论中提供巨大帮助之后(再次感谢),以下是该问题的解决方案:

In my first activity I have the following in my onItemClick for my ListView: 在我的第一个活动中,我的ListView的onItemClick中包含以下内容:

public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

        HashMap<String, String> hashmap = (HashMap)parent.getItemAtPosition(position);
        Intent intent = new Intent (parent.getContext(), SECONDACTIVITY.class);
        intent.putExtra("key", hashmap);
        startActivityForResult(intent, 0);
    }
}

In my second activity I then used this piece of code in the onCreate: 在第二个活动中,我在onCreate中使用了这段代码:

Bundle bundle = getIntent().getExtras();
        if(bundle!=null) {
            HashMap<String, String> vals = (HashMap)bundle.getSerializable("key");
            et1.setText(vals.get("value1"));
            et2.setText(vals.get("value2"));
        }

You could retrieve the data for the parent adapterview, something like { parent.getItem(position) } and send that through the intent (instead of retrieving all the data from the controller). 您可以检索父adapterview的数据,类似于{parent.getItem(position)},然后通过意图将其发送(而不是从控制器中检索所有数据)。 On the next activity you'd iterate through the hashmap items and set them to the apropriate EditTexts. 在下一个活动中,您将遍历hashmap项并将它们设置为适当的EditTexts。

Edit: On your public void onItemClick(...) you should probably use: 编辑:在您的public void onItemClick(...)您可能应该使用:

HashMap<String, String> yourHashMap = parent.getItemAtPosition(position); Intent intent = new Intent (parent.getContext(), Record.class); intent.putSerializable("key", yourHashMap);

And on the next activity: 在下一个活动中:

Bundle bundle = getIntent().getExtras(); if(bundle!=null) { HashMap<String, String> vals = (HashMap)bundle.getSerializable("key"); ((TextView)findViewById(R.id.txt1)).setText(vals.get("value1")); ((TextView)findViewById(R.id.txt2)).setText(vals.get("value2")); ((TextView)findViewById(R.id.txt3)).setText(vals.get("value3")); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从列表视图传递到另一个活动的edittext - Passing data from listview to edittext of another activity 使用从SQLite导出的数据填充RecyclerView / ListView - Populate RecyclerView/ListView with data generalized from SQLite 将sqlite数据从列表视图传递到其他活动 - Passing sqlite data from listview to other activity 将Firebase数据从ListView传递到单独的活动editText - Passing firebase data from ListView to seperate activity editText Android Spreadsheet数据放入ArrayList HashMap中填充ListView - Android Spreadsheet data into ArrayList HashMap populate ListView 从ArrayList <HashMap <String,String >>填充ListView - Populate a ListView from an ArrayList<HashMap<String, String>> 如何使用 ImageView 将现有 sqlite 数据库中的数据填充到 ListView - How to populate data from existing sqlite database to ListView with ImageView ListView的新活动 - New Activity from ListView 如何通过单击按钮将Listview中的数据传递到购物车列表(新活动)。 我插入列表视图的数据正在使用SQLite - How to pass the data in Listview to Cart list (new activity) by click on button . My data inserted to listview is using SQLite 从ListView获取Activity中EditText的值 - Getting value of EditText in Activity from ListView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM