我想知道,有任何标准视图(imageview,imagebutton,textview,按钮等)隐藏的价值吗?所以我需要设置每个项目的这个值,然后,例如,从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)
答案 0 :(得分:0)
为了设置任何View实例的可见性,您可以这样做:
View myView = (View)findViewById(R.id.myview);
myView.setVisibility(View.GONE);
//or
myView.setVisibility(View.VISIBLE);
//or
myView.setVisibility(View.HIDDEN);
您可以在此处查看文档:{{3}}
答案 1 :(得分:0)
您可以将setContentDescription(String str)和getContentDescription()与您提到的所有视图一起使用。
BUT
这不是处理此事的正确方法。你应该扩展视图类或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))调用它;