我创建了一个listView,其中有2个Item_separator和多个item_element。 我想隐藏我的item_element的一部分,然后点击我的Item_separator的减号按钮元素(被红色包围的元素),如下所示:
这是我的项目元素布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="@+id/Item_Layout_Container">
<!-- Icon -->
<RelativeLayout
android:id="@+id/Item_Layout_Icon"
android:layout_width="81dp"
android:layout_height="79dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp"
android:background="@drawable/green_circle">
<ImageView
android:id="@+id/icon_symbol"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<!-- Title -->
<TextView
style="@style/AppTheme.Text.Large"
android:id="@+id/Item_Layout_Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/Item_Layout_Icon"
android:layout_toRightOf="@+id/Item_Layout_Icon"
android:text="Title"
/>
<!-- Description -->
<TextView
style="@style/AppTheme.Text.Medium"
android:id="@+id/Item_Layout_Description"
android:layout_below="@id/Item_Layout_Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="description"
android:layout_toRightOf="@+id/Item_Layout_Icon"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="15.30"
android:id="@+id/Item_Layout_Time"
android:layout_below="@+id/Item_Layout_Icon"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/Item_Layout_Icon"
android:layout_alignEnd="@+id/Item_Layout_Icon"
android:gravity="center" />
</RelativeLayout>
在我的活动中,我使用了一个适配器来设置我的元素,我尝试这样做但它不起作用:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ITEM:
convertView = mInflater.inflate(R.layout.item_layout, null);
holder.Title = (TextView) convertView.findViewById(R.id.Item_Layout_Title);
holder.Description = (TextView) convertView.findViewById(R.id.Item_Layout_Description);
holder.Time = (TextView) convertView.findViewById(R.id.Item_Layout_Time);
holder.Icon = (RelativeLayout) convertView.findViewById(R.id.Item_Layout_Icon);
holder.IconState = (ImageView) convertView.findViewById(R.id.icon_symbol);
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.separator, null);
holder.Title = (TextView) convertView.findViewById(R.id.textSeparator);
holder.ButtonHide = (Button) convertView.findViewById(R.id.btnminus)
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
switch (type) {
case TYPE_ITEM:
holder.Title.setText(mData.get(position).title);
holder.Description.setText(mData.get(position).description);
holder.Time.setText(mData.get(position).time);
holder.Icon.setBackgroundResource(mData.get(position).iconLayout);
holder.IconState.setImageResource(mData.get(position).iconImage);
holder.Icon.setTag(mData.get(position).iconLayout);
holder.Icon.setOnClickListener(myImageClickListener);
break;
case TYPE_SEPARATOR:
holder.Title.setText(mData.get(position).title);
textTag = mData.get(position).title;
holder.ButtonHide.setOnClickListener(hideElement);
break;
}
return convertView;
}
public View.OnClickListener hideElement = new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setVisibility(View.GONE);
}
};
这是一个测试,但它不起作用;如何在第二个item_separator之后隐藏元素?谢谢
答案 0 :(得分:0)
使用SearchResponse response = client.prepareSearch("my_index")
.setTypes("my_output")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.queryStringQuery(query))
.setFrom(page).setSize(size)
.execute()
.actionGet();
,您应该使用此块GONE容器。这样的事情:v.setVisibility(View.GONE);
你可以这样做:
public View.OnClickListener hideElement = new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.Description.setVisibility(View.GONE);
}
};
并使用它:private class OnHideElementClickListener implements View.OnClickListener {
private TextView mDescriptionBlockText;
public OnHideElementClickListener(TextView descriptionBlock) {
mDescriptionBlockText = descriptionBlock;
}
@Override
public void onClick(View v) {
mDescriptionBlockText.setVisibility(View.GONE);
}
}
答案 1 :(得分:0)
您应该使用
v.setVisibility(View.GONE);
而不是
v.setVisibility(View.INVISIBLE);
根据我的建议,如果你想隐藏视图,最好使用LinearLayout而不是RelativeLayout