如果一个孩子为空(在expandable listview
填充并使用external sqlite database
的{{1}}中,我试图将view(在list_child中)设置为不可见。 />我试图这样做:
1.在simplecursortreeadapater
内初始化视图,并在viewbinder class
中设置条件。.但是我得到了view.setvisibility的空指针(当应用崩溃时)..我在做什么错?谢谢
case.child2
list_child.xml
public class MyViewBinder implements SimpleCursorTreeAdapter.ViewBinder {
View view1=(View)findViewById(R.id.view1);
@Override
public boolean setViewValue(View view, final Cursor cursor, int columnIndex) {
int viewID = view.getId();
switch (viewID) {
case R.id.group1:
TextView groupName = (TextView) view;
String groupname;
groupname = cursor.getString(cursor.getColumnIndex(Database.DATABASE_GROUP_1));
groupName.setText(Html.fromHtml(groupname));
break;
case R.id.child1:
TextView friendName = (TextView) view;
String friend_name;
friend_name = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_1));
friendName.setText(Html.fromHtml(friend_name));
break;
case R.id.child2:
final ImageView url = (ImageView) view;
final String urls;
urls = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_2));
if (urls != null) {
Glide.with(AnatomyNostrils.this).load(urls).apply(new RequestOptions().dontTransform().format(DecodeFormat.PREFER_ARGB_8888)).into(url);
view.findViewById(R.id.child2).setVisibility(View.VISIBLE);
view1.setVisibility(View.VISIBLE);
} else {
view.findViewById(R.id.child2).setVisibility(View.GONE);
view1.setVisibility(View.GONE);
}
url.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(AnatomyNostrils.this);
View mView = getLayoutInflater().inflate(R.layout.dialog_custom_layout, null);
PhotoView photoView = mView.findViewById(R.id.imageView);
photoView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
photoView.setImageDrawable(((ImageView) view).getDrawable());
Glide.with(AnatomyNostrils.this).load(urls).apply(new RequestOptions().dontTransform().format(DecodeFormat.PREFER_ARGB_8888)).into(photoView);
mBuilder.setView(mView);
AlertDialog mDialog = mBuilder.create();
mDialog.show();
}
});
break;
来自仿真器的图像:https://i.imgur.com/cj9dWSX.png
答案 0 :(得分:0)
如果执行了export class AppComponent {
addClass(id: any) {
this.id = id;
}
...
中的代码,则case R.id.child2:
是要显示/隐藏的视图,因此请替换:
view
具有:
view.findViewById(R.id.child2).setVisibility(...);