如果允许,我对数组列表有两个问题 我导入存储在SharedPreferences中的值并将它们显示在数组列表中 但是,来自SharedPreferences的值为空并在数组中显示,我不希望空白值在数组中显示为空,如图像中所示 enter image description here
我把这个条件但它没有用我认为这是错的,有人能给我正确的代码来解决这个问题
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_order );
textView = (TextView) findViewById( R.id.quantityId );
lv = (ListView) findViewById( R.id.list_view );
sharedPreferences = getSharedPreferences( "blanche",Context.MODE_PRIVATE );
chickenBlanche = sharedPreferences.getString( "blancheS","" );
SharedPreferences philadelph = getSharedPreferences( "philadelphia",Context.MODE_PRIVATE );
philadelphiaCheese = philadelph.getString( "philadelphiaS","" );
SharedPreferences mushroom = getSharedPreferences( "mushroom",Context.MODE_PRIVATE );
mushroomS = mushroom.getString( "mushroomS","" );
SharedPreferences superOf = getSharedPreferences( "super",Context.MODE_PRIVATE );
superS = superOf.getString( "superS","" );
SharedPreferences primo = getSharedPreferences( "primo",Context.MODE_PRIVATE );
primoo = primo.getString( "primoS","" );
SharedPreferences organo = getSharedPreferences( "oregano",Context.MODE_PRIVATE );
oregano = organo.getString( "oreganoS","" );
SharedPreferences pizzaMush = getSharedPreferences( "pizzaMushroom",Context.MODE_PRIVATE );
pizzaMushS = pizzaMush.getString( "pizzaMushroomS","" );
SharedPreferences cheesePizza = getSharedPreferences( "pizzaCheese",Context.MODE_PRIVATE );
pizzaChesse = cheesePizza.getString( "pizzaCheeseS","" );
SharedPreferences peproni = getSharedPreferences( "peproni",Context.MODE_PRIVATE );
pepproni = peproni.getString( "peproniS","" );
SharedPreferences forSeason = getSharedPreferences( "fourSeasons",Context.MODE_PRIVATE );
fourSeasons = forSeason.getString( "fourSeasonsS","" );
SharedPreferences italianPiz = getSharedPreferences( "italian",Context.MODE_PRIVATE );
italianPi = italianPiz.getString( "italianS","" );
SharedPreferences hotPiz = getSharedPreferences( "hotDog",Context.MODE_PRIVATE );
hotDog = hotPiz.getString( "hotDogS","" );
values = new ArrayList<String>();
values.add( chickenBlanche );
values.add( philadelphiaCheese );
values.add( mushroomS );
values.add( superS );
values.add( primoo );
values.add( oregano );
values.add( pizzaMushS );
values.add( pizzaChesse );
values.add( pepproni );
values.add( fourSeasons );
values.add( italianPi );
values.add( hotDog );
boolean retval = chickenBlanche.isEmpty();
if (retval == true) {
textView.setVisibility( View.GONE );
} else {
textView.setVisibility( View.VISIBLE );
}
boolean retval1 = philadelphiaCheese.isEmpty();
if (retval1 == true) {
textView.setVisibility( View.GONE );
} else {
textView.setVisibility( View.VISIBLE );
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>( this,R.layout.row_item,R.id.quantityId,values );
lv.setAdapter( adapter );
在Xml文件夹中,我想将listview放在滚动视图中,但设计也不能正常工作 我想将列表视图放在滚动视图中,其中包含许多其他优惠,例如文本视图和EditText 这是xml代码
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:orientation="vertical"
android:weightSum="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="ka.noga.finalproject.Order"
tools:showIn="@layout/app_bar_order">
<TextView
android:id="@+id/your_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/your_order"
android:padding="15dp"
android:textSize="25sp"
android:gravity="center"
android:textColor="@color/colorAccent"/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:layout_margin="15dp"
android:dividerHeight="1dp"
android:textSize="15sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<EditText
android:id="@+id/comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="@string/comment"
android:textSize="15sp"
android:textColor="#000000"/>
<TextView
android:id="@+id/comments"
android:layout_weight="0.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="@string/bill"
android:textColor="@color/colorAccent"
android:gravity="center"
android:textSize="20sp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subtotal"
android:textSize="15sp"
android:layout_alignParentLeft="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="8dp"
android:id="@+id/subtotal"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/service_fee"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="8dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/subtotal"
android:text="@string/service_fee"
android:textSize="15sp"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/vat"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="8dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/service_fee"
android:text="@string/vat"
android:textSize="15sp"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/delivery_fee"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="8dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/vat"
android:text="@string/delivery_fee"
android:textSize="15sp"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/price"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:paddingBottom="8dp"
android:layout_alignParentRight="true"
android:hint="@string/price"
android:textSize="18sp"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/price_1"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:paddingBottom="8dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/price"
android:text="@string/price_1"
android:textSize="18sp"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/price_2"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:paddingBottom="8dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/price_1"
android:text="@string/price_2"
android:textSize="18sp"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/price_3"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:paddingBottom="8dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/price_2"
android:text="@string/price_3"
android:textSize="18sp"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/delivery_fee"
android:padding="15dp"
android:text="@string/total"
android:textColor="#000000"
android:textSize="25sp" />
<TextView
android:id="@+id/subtotal_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subtotal_price"
android:padding="15dp"
android:textSize="25sp"
android:layout_alignParentRight="true"
android:layout_below="@+id/price_3"
android:textColor="#000000"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/some_info"
android:textSize="18sp"
android:layout_weight="0.2"
android:textColor="@color/colorAccent"
android:padding="15dp"
android:gravity="center_horizontal"
android:id="@+id/someInfo"/>
<EditText
android:id="@+id/name"
android:layout_weight="0.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/your_name"
android:layout_margin="15dp"
android:inputType="textCapWords"/>
<EditText
android:id="@+id/address"
android:layout_weight="0.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/your_address"
android:layout_margin="15dp"
android:inputType="textCapWords"/>
<EditText
android:id="@+id/phone_number"
android:layout_weight="0.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone_number"
android:layout_margin="15dp"
android:inputType="phone"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/send_order_by"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/send_order_by"
android:textSize="20sp"
android:padding="10dp"
android:gravity="center"
android:textAllCaps="true"
android:textColor="@color/colorAccent"
/>
<ImageView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/send_order_by"
android:layout_margin="45dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
/>
<ImageView
android:id="@+id/whatsapp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/send_order_by"
android:layout_margin="45dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
iabbrev { <c-r>=RailsExpand('{', "{\<lt>cr>}\<lt>c-o>O\<tab>")<cr>