【发布时间】:2018-08-18 13:20:32
【问题描述】:
如果一个孩子为空,我正在尝试将一个视图(在 list_child 中)设置为不可见(在由 external sqlite database 填充并使用 simplecursortreeadapater 的 expandable listview 中)..
我试图这样做像这样:
1.初始化viewbinder class中的视图和2.在case.child2中设置条件..但是我得到了view.setvisibility的空指针(当应用程序崩溃时)..我做错了什么?谢谢
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;
list_child.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dp">
<TextView
android:id="@+id/child1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/textsizechildexpandablelistview"
android:textIsSelectable="true"
android:paddingBottom="5dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="2dp"
android:textColor="@android:color/black"
/>
<LinearLayout
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/child1"
android:visibility="visible"
android:orientation="horizontal">
<ImageView
android:layout_weight="1"
android:id="@+id/child3"
android:layout_width="match_parent"
android:layout_height="@dimen/heightimageviewchildexpandablelistview"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp" />
<View
android:layout_width="1dp"
android:id="@+id/view2"
android:layout_height="match_parent"
android:layout_margin="6dp"
android:background="#cc0033" />
<ImageView
android:layout_weight="1"
android:id="@+id/child2"
android:layout_width="match_parent"
android:layout_height="@dimen/heightimageviewchildexpandablelistview"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp" />
<View
android:layout_width="1dp"
android:id="@+id/view1"
android:layout_height="match_parent"
android:layout_margin="6dp"
android:background="#cc0033" />
</LinearLayout>
来自模拟器的图片:https://i.imgur.com/cj9dWSX.png
【问题讨论】:
-
没有人知道答案
标签: android simplecursortreeadapter