水平列表视图适配器如下所示。当我单击列表项视图然后隐藏它时,其他列表项位置正在隐藏。
// get view method and item row inflating
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
holder = new ViewHolder() ;
convertView = inflater.inflate(R.layout.viewitem, null) ;
holder.rootLayout = (LinearLayout) convertView.findViewById(R.id.animation_root_layout) ;
holder.frontLayout = (LinearLayout) convertView.findViewById(R.id.ticket_front_layout) ;
holder.backLayout = (LinearLayout) convertView.findViewById(R.id.ticket_back_layout) ;
holder.backLayout.setVisibility(View.GONE);
holder.passDetails = (TextView) convertView.findViewById(R.id.passenger_details_button) ;
holder.ticketDetails = (TextView) convertView.findViewById(R.id.ticket_details_button) ;
holder.passDetails.setTag(position); // set the tag to item
holder.ticketDetails.setTag(position);
holder.frontLayout.setTag(position);
holder.backLayout.setTag(position);
convertView.setTag(R.layout.viewitem,holder); // set the tag to view
} else {
holder = (ViewHolder) convertView.getTag(R.layout.viewitem) ;
}
holder.passDetails.setText("P Details : "+position);
holder.ticketDetails.setText("T Details : "+position);
// setting click listener on list item that is a linear layout
holder.passDetails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int which = -1;
Object obj = v.getTag();
if(obj instanceof Integer) {
which = ((Integer)obj).intValue();
}
if(which >-1){
// on click visibility view or gone
holder.frontLayout.setVisibility(View.GONE);
holder.backLayout.setVisibility(View.VISIBLE);
}
}
});
// setting click listener on list item that is a linear layout second
holder.ticketDetails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (customListner != null) {
int which = -1;
Object obj = v.getTag();
if(obj instanceof Integer) {
which = ((Integer)obj).intValue();
}
if(which >-1) {
holder.frontLayout.setVisibility(View.VISIBLE);
holder.backLayout.setVisibility(View.GONE);
}
}
}
});
return convertView ;
}
// view holder for the list variables
public class ViewHolder {
ImageView refresh, share ;
TextView passDetails, ticketDetails ;
LinearLayout frontLayout , backLayout, rootLayout ;
}
在上面的代码中,当我点击水平列表项以隐藏它时,它会隐藏其他项位置。如何仅在水平列表项中隐藏确切位置单击
这是布局xml文件(viewitem.xml): 在这里我有行项目布局,这包含两个线性布局,第一个是可见性可见,第二个可见性消失。
我希望在从适配器以编程方式单击项目时显示第二个线性布局并隐藏第一个布局。
但我遇到的问题是当我点击列表视图的项目时,首先一个可见性消失但第二个布局不可见。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/animation_root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ticket_front_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="parvindra"
android:gravity="center"
android:id="@+id/passenger_details_button"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ticket_back_layout"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="singh"
android:gravity="center"
android:id="@+id/ticket_details_button"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>