我有一個列表,我有一個圖像視圖。我只需要顯示該圖像時,我的一個變量是真實的。實際上,我做了一個自定義適配器,其中我有一個變量「serviceAlertPresent」。如果這是真的,我需要以顯示圖像elese我不想在行上顯示圖像。我將如何實現這一點如何在android中的listview中隱藏和顯示圖像?
這是我的每行代碼。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/transparent"
android:padding="5dp" >
<TextView
android:id="@+id/item_platform"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:text="Ptf."
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/item_schDepart"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/item_platform"
android:layout_alignBottom="@+id/item_platform"
android:layout_toRightOf="@+id/item_platform"
android:text="dpt"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/item_arrival"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/item_schDepart"
android:layout_alignBottom="@+id/item_schDepart"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/item_expectdepart"
android:text="Arr."
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/item_expectdepart"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_below="@+id/item_schDepart"
android:layout_marginTop="14dp"
android:layout_toRightOf="@+id/item_platform"
android:text="Expert"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/item_expertarrival"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/item_expectdepart"
android:layout_alignBottom="@+id/item_expectdepart"
android:layout_alignLeft="@+id/item_arrival"
android:text="exprt Arrival"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/item_stationName"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/item_arrival"
android:layout_alignBottom="@+id/item_arrival"
android:layout_marginLeft="17dp"
android:layout_toRightOf="@+id/item_expertarrival"
android:text="Des."
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/alertStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@+id/item_stationName"
android:src="@drawable/alert_icon" />
</RelativeLayout>
這裏是自定義適配器
public class CustomListAdapter extends BaseAdapter{
ArrayList<deparaturedaseboarddto> deparaturedaseboarddto;
private Context context;
public CustomListAdapter(Context context, ArrayList<deparaturedaseboarddto> deparaturedaseboarddto){
this.deparaturedaseboarddto=deparaturedaseboarddto;
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return deparaturedaseboarddto.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return deparaturedaseboarddto.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if (v == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = mInflater.inflate(R.layout.row_listitem, null);
}
final TextView platFormName = (TextView) v
.findViewById(R.id.item_platform);
final TextView schDepart = (TextView) v
.findViewById(R.id.item_schDepart);
final TextView expDepart = (TextView) v
.findViewById(R.id.item_expectdepart);
final TextView arrival = (TextView) v
.findViewById(R.id.item_arrival);
final TextView exparrival = (TextView) v
.findViewById(R.id.item_expertarrival);
final TextView stationName = (TextView) v
.findViewById(R.id.item_stationName);
final String platformValue = deparaturedaseboarddto.get(position).getPlatformNo();
final String schDepartValue= deparaturedaseboarddto.get(position).getSchDepart();
final String schExpectValue= deparaturedaseboarddto.get(position).getExpDepart();
final String arrivalValue= deparaturedaseboarddto.get(position).getDestSchArrival();
final String exparrivalValue= deparaturedaseboarddto.get(position).getDestSchArrival();
String stationNameValue= deparaturedaseboarddto.get(position).getDestinationStation().getStationName();
platFormName.setText(platformValue);
schDepart.setText(schDepartValue);
expDepart.setText(schExpectValue);
arrival.setText(arrivalValue);
exparrival.setText(exparrivalValue);
stationName.setText(stationNameValue);
return v;
}
public void referhList(ArrayList<deparaturedaseboarddto> deparaturedaseboarddto){
this.deparaturedaseboarddto=deparaturedaseboarddto;
notifyDataSetChanged();
}
}
我問這個圖像視圖
<ImageView
android:id="@+id/alertStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@+id/item_stationName"
android:src="@drawable/alert_icon" />
我需要證明這個時候「serviceAlertPresent」。我會得到這樣的值deparaturedaseboarddto.get(position).isServiceAlertPresent()
setVisibility接受可見,不可見或不可見的int值。 – 2014-10-27 09:52:14
@PareshMayani,哦,抱歉的人,我的錯誤。你是對的..謝謝。 – Akhil 2014-10-27 09:53:59