如何从具有两列的自定义 ListView 中获取值到下一个 Activity 中的 Simple 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);