0

我想知道,是否有任何标准视图(imageview、imagebutton、textview、button 等)类似于隐藏值?所以我需要为每个项目设置这个值,然后,例如,在 onclick 事件中从视图中获取它。

错误日志

07-11 13:06:23.263: ERROR/AndroidRuntime(989): Uncaught handler: thread main exiting due to uncaught exception
07-11 13:06:23.273: ERROR/AndroidRuntime(989): java.lang.NullPointerException
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at com.artox.relax.inf.RestaurantListBaseActivity$RestaurantListAdapter.getView(RestaurantListBaseActivity.java:95)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.AbsListView.obtainView(AbsListView.java:1274)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.ListView.makeAndAddView(ListView.java:1668)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.ListView.fillDown(ListView.java:637)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.ListView.fillFromTop(ListView.java:694)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.ListView.layoutChildren(ListView.java:1521)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.AbsListView.onLayout(AbsListView.java:1113)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.View.layout(View.java:6830)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.View.layout(View.java:6830)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.View.layout(View.java:6830)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:900)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.View.layout(View.java:6830)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.View.layout(View.java:6830)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.View.layout(View.java:6830)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.ViewRoot.performTraversals(ViewRoot.java:996)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.os.Looper.loop(Looper.java:123)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at java.lang.reflect.Method.invokeNative(Native Method)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at java.lang.reflect.Method.invoke(Method.java:521)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-11 13:06:23.273: ERROR/AndroidRuntime(989):     at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

0

为了设置任何 View 实例的可见性,您可以执行以下操作:

View myView = (View)findViewById(R.id.myview);
myView.setVisibility(View.GONE);
//or
myView.setVisibility(View.VISIBLE);
//or
myView.setVisibility(View.HIDDEN);

您可以在此处查看文档:http: //developer.android.com/reference/android/view/View.html#setVisibility%28int%29

于 2012-07-11T10:05:51.133 回答
0

您可以将 setContentDescription(String str) 和 getContentDescription() 与您提到的所有视图一起使用。

那不是处理此事的正确方法。您应该扩展视图类或 onclicklistener

例如:

 public class myClickListener implements View.OnClickListener{

        private int hiddenValue;
        public myClickListener(int hiddenValue){
            this.hiddenValue=hiddenValue;
        }

        @Override
        public void onClick(View v) {
            hiddenValue++;
        }

    }

然后你用 .setonlicklistener(new myClickListener(5)); 调用它

于 2012-07-11T10:51:01.440 回答