gpt4 book ai didi

android - 我可以在下一个 Activity 中将字符串值从 MultitiColumn listView 存储到 Simple ListView 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:55 26 4
gpt4 key购买 nike

如何在下一个 Activity 中从具有两列的自定义 ListView 获取值到简单 ListView。我有 select1 和 select2 String[] 变量。Myval 是全局变量。我有以下异常 *

logcat 中的异常:

    07-31 10:37:55.470: E/AndroidRuntime(974): FATAL EXCEPTION: main
07-31 10:37:55.470: E/AndroidRuntime(974): java.lang.NullPointerException
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.ListView.makeAndAddView(ListView.java:1772)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.ListView.fillDown(ListView.java:672)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.ListView.fillFromTop(ListView.java:732)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.ListView.layoutChildren(ListView.java:1625)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.View.layout(View.java:11278)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.View.layout(View.java:11278)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.View.layout(View.java:11278)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.View.layout(View.java:11278)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.View.layout(View.java:11278)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.os.Looper.loop(Looper.java:137)
07-31 10:37:55.470: E/AndroidRuntime(974): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-31 10:37:55.470: E/AndroidRuntime(974): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 10:37:55.470: E/AndroidRuntime(974): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 10:37:55.470: E/AndroidRuntime(974): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-31 10:37:55.470: E/AndroidRuntime(974): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-31 10:37:55.470: E/AndroidRuntime(974): at dalvik.system.NativeStart.main(Native Method)

从 Spinner 获取值:

     public void onItemSelected(AdapterView<?> parent, View arg1, int pos,long id) {              


String Text = parent.getSelectedItem().toString();
if(Text.equals("----SELECT----")) {

}
else if(Text.equals("BEVERAGES")){
select1=new String[Beverage.length];
select2=new String[P1.length];
System.out.println("Length of Beverage:" + select1.length);
System.out.println("Length of P1:" + select2.length);
select1 = Beverage;
select2 = P1;
l1.setAdapter(new EfficientAdapter(HomeActivity.this));
return;

}

从自定义ListView获取值:

                  l1.setOnItemClickListener(new OnItemClickListener() { 

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

// When clicked, show a toast with the TextView text
Toast.makeText(HomeActivity.this, "SELECTED :: " + "item "+select1[position] + " " + "price"+ select2[position],
Toast.LENGTH_SHORT).show();
String ss=(String)parent.getItemAtPosition(position);
GlobalClass.myval.add(ss);

最佳答案

在您的代码中替换以下内容,它可能会为您提供一些
l1.setAdapter(new EfficientAdapter(HomeActivity.this)); 用。。。来代替 : l1.setAdapter(new EfficientAdapter(HomeActivity.this),arraytosendtoadapter);
//将您的高效适配器更改为具有 String[] 以便接收您发送的内容

关于android - 我可以在下一个 Activity 中将字符串值从 MultitiColumn listView 存储到 Simple ListView 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11734123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com