使用 Bundle 将数组数据传递给 listview click 上的另一个活动

     2023-04-15     185

关键词:

【中文标题】使用 Bundle 将数组数据传递给 listview click 上的另一个活动【英文标题】:Passing Array Data Using Bundle to another activity on listview click 【发布时间】:2016-10-04 06:49:41 【问题描述】:

您好,我一直在尝试将数组数据从一个 Activity 传递到另一个没有正面响应,因为我不知道如何通过捆绑传递它已在列表视图上单击的数据并将其提取到另一个 Activity .

 public class Hospitals extends Fragment 
View hospitalZetu;
Context context;




public Hospitals() 
    // Required empty public constructor


@Override
public void onCreate(Bundle savedInstanceState) 
    super.onCreate(savedInstanceState);


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) 
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_hospitals, container, false);

    final ArrayList<Data> hospitalsDetails = new ArrayList<Data>();

    HospitalAdaptor adapter = new HospitalAdaptor(getContext(), hospitalsDetails);

    ListView listView;
    listView = (ListView) view.findViewById(R.id.edis_hospitals);


    hospitalsDetails.add(new Data(12.122,12.0,R.drawable.h1,"Muhimbili Hospital","12","23","12","90"));
    hospitalsDetails.add(new Data(12.122,12.0,R.drawable.h2,"Aghakan Hospital","10","43","76","90"));

    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() 
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) 

            Data data = hospitalsDetails.get(position);
            Intent intent = new Intent(getActivity(),Hopital.class);
            Bundle bundle = new Bundle();
            bundle.putString("Hname", String.valueOf(data));
            intent.putExtras(bundle);
            startActivity(intent);

        
    );

    return view;

【问题讨论】:

有什么问题?您似乎正确地传递了数据。 “数据”是您创建的自定义类吗? 你有使用可序列化的数据类吗? 可序列化或可打包? Have a look on this example 【参考方案1】:

我觉得应该是的

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

        Data data = hospitalsDetails.get(position);
        Intent intent = new Intent(Hospital.this,"anotherActivity.class");
        intent.putExtra("Hname", String.valueOf(data));
        startActivity(intent);

    

【讨论】:

谢谢 那我将如何提取 anotheractivity.class 中的数据

将php变量/数组数据传递给角度js

...ularjs【发布时间】:2015-09-2213:53:12【问题描述】:我正在使用php数据库连接,将“$row”作为一个数组,将名称作为一个字段存储在其中。但是经过大量搜索后,我知道如何在angularjs中传递php变量这是代码,我正在努力实现。我... 查看详情

Laravel Blade 将数组数据传递给多个扩展

...】:我在互联网上搜索了很多,但无法找到答案。我正在使用Laravel5,刀片模板几乎没有问题,因为在我的项目中我需要某个时间进行多次扩展,并且我需要将所有数据从一个布局传递到所有主布局“扩展”嵌套页面示例:@extend... 查看详情

如何通过数组将数据传递给表格视图?

】如何通过数组将数据传递给表格视图?【英文标题】:Howtopassdatatotableviewbyarray?【发布时间】:2011-05-3104:18:08【问题描述】:我想将字符串传递给表格视图。在第一,我可以传递给表格视图,但如果我将第二个字符串传递给表... 查看详情

将更新的数组数据传递给 uipickerview

】将更新的数组数据传递给uipickerview【英文标题】:Passingupdatedarraydatatouipickerview【发布时间】:2019-11-2102:26:04【问题描述】:对于swift来说还是个新手,我在将更新的数据传递到pickerview时遇到了一些麻烦。我收到“索引超出范... 查看详情

如何将数组作为表单数据传递给 Postman

】如何将数组作为表单数据传递给Postman【英文标题】:HowtopassarraytoPostmanasform-data【发布时间】:2021-06-0914:56:58【问题描述】:我想在Postman中测试以下URL。但是,我想分解数组以便于测试,例如作为表单数据(或其他)。如何在... 查看详情

将数组数据传递给循环中的变量

】将数组数据传递给循环中的变量【英文标题】:Passingarraydatatoavariableinaloop【发布时间】:2019-01-1415:59:39【问题描述】:如何在循环中将$the_slug的内容传递给$post_name变量?$tags=get_the_tags();foreach($tagsas$tag)global$post;$the_slug=$tag->s... 查看详情

如何将 ViewController 中的数组数据传递给 UICollectionView 自定义单元格?

】如何将ViewController中的数组数据传递给UICollectionView自定义单元格?【英文标题】:HowtopassarraydatainsideViewControllertoUICollectionViewCustomCell?【发布时间】:2016-06-2304:54:23【问题描述】:我正在自定义“UICollectionViewCell”中创建一个tab... 查看详情

如何将数据传递给 kthread_run

...【发布时间】:2019-10-0714:33:29【问题描述】:我正在尝试使用多线程制作简单的内核模块。所以我使用的是linux/kthread.h,内核v.5.2.11问题:我无法将char数组传递给线程:分段错误。这就是我正在做的:typedefstructintnum;charorigin[MAXST... 查看详情

使用反应钩子将数据传递给兄弟组件?

】使用反应钩子将数据传递给兄弟组件?【英文标题】:Passingdatatosiblingcomponentswithreacthooks?【发布时间】:2020-09-0207:08:01【问题描述】:我想将变量username从sibling1组件传递给sibling2组件并在那里显示。Sibling1组件:constsibling1=(user... 查看详情

使用 jQuery post 使用 Laravel 将动态数据传递给引导模式

】使用jQuerypost使用Laravel将动态数据传递给引导模式【英文标题】:PassingdynamicdatatobootstrapmodalwithLaravelusingjQuerypost【发布时间】:2017-10-1403:26:46【问题描述】:我正在尝试将动态数据传递给引导模式。我想要做的是通过使用jQuery... 查看详情

使用 ngOnChanges 将异步数据传递给子组件不起作用

】使用ngOnChanges将异步数据传递给子组件不起作用【英文标题】:PassasyncdatatochildcomponentwithngOnChangesdoesnotwork【发布时间】:2019-11-1306:52:48【问题描述】:按照thistutorial,正是解决方案n2,我尝试以这种方式将异步数据传递给子组... 查看详情

角度将数据传递给变量以及该变量的使用

】角度将数据传递给变量以及该变量的使用【英文标题】:Angularpassingdatatovariableandthatvariableusage【发布时间】:2020-09-1817:29:44【问题描述】:声明变量exportclassTestComponentimplementsOnInittestVar:string;然后初始化ngOnInit()this.somefunctionworks... 查看详情

如何将变量数据传递给 createFragementContainer

...tainer【发布时间】:2018-04-0613:45:15【问题描述】:我正在使用RelayModern构建我的组件,我想将一个变量传递给片段,以便它可以用作我的查询中的GraphQL参数。这是我正在使用的代码:classTestextendsComponentsta 查看详情

我可以使用花括号将数据传递给刀片组件吗?

】我可以使用花括号将数据传递给刀片组件吗?【英文标题】:CanIpassdatatobladecomponentbyusedcurlybraces?【发布时间】:2022-01-2403:42:10【问题描述】:我正在尝试实现一种功能切换以与我的组件一起使用。我想知道是否可以通过使用... 查看详情

在同一视图中使用多个模型时将表单数据传递给模型

】在同一视图中使用多个模型时将表单数据传递给模型【英文标题】:Passingformdatatoamodelwhenusingmultiplemodelsinthesameview【发布时间】:2021-12-2614:26:03【问题描述】:当我在一个视图中有多个模型时,您如何将表单数据传递给模型(... 查看详情

java使用接口将数据传递给主线程(代码片段)

查看详情

导航架构组件 - 使用 Fragment 将参数数据传递给 startDestination

】导航架构组件-使用Fragment将参数数据传递给startDestination【英文标题】:NavigationArchitectureComponent-PassingargumentdatatothestartDestinationwithFragment【发布时间】:2020-08-0612:40:57【问题描述】:我有一个fragmentA,其中包含以下代码:<Rela... 查看详情

将异步获取的数据传递给子道具

...列新闻项目并将它们显示在页面上。我有端点,并且可以使用$.getJSON()进行成功的调用,控制台日志证明了这一点。我将此调用放入父组件中,因为子组件将需要使用数据。但是,当我将此数据传递给子组件时, 查看详情