Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果数组列表的值为空_Java_Android - Fatal编程技术网

Java 如果数组列表的值为空

Java 如果数组列表的值为空,java,android,Java,Android,如果允许,我对数组列表有两个问题 我导入存储在SharedReferences中的值,并将它们显示在数组列表中 但是有一些来自SharedReferences的值是空的,并且显示在数组中,我不希望空白值在数组中显示为空,如图所示 我把这个条件,但它没有工作,我认为这是错误的,谁能给我正确的代码来解决这个问题 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate( savedInsta

如果允许,我对数组列表有两个问题 我导入存储在SharedReferences中的值,并将它们显示在数组列表中 但是有一些来自SharedReferences的值是空的,并且显示在数组中,我不希望空白值在数组中显示为空,如图所示

我把这个条件,但它没有工作,我认为这是错误的,谁能给我正确的代码来解决这个问题

@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 );
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
textView=(textView)findViewById(R.id.quantityId);
lv=(ListView)findViewById(R.id.list\u视图);
SharedReferences=GetSharedReferences(“blanche”,Context.MODE\u PRIVATE);
chickenBlanche=sharedPreferences.getString(“blancheS”,“blancheS”);
SharedReferences philadelph=GetSharedReferences(“philadelphia”,Context.MODE\u PRIVATE);
Philadelphacheese=philadelph.getString(“philadelphiaS”,”);
SharedReferences蘑菇=GetSharedReferences(“蘑菇”,Context.MODE\u PRIVATE);
蘑菇=蘑菇.getString(“蘑菇”,“蘑菇”);
SharedReferences superOf=getSharedReferences(“super”,Context.MODE\u PRIVATE);
superss=supersof.getString(“superss”,即“”);
SharedReferences primo=getSharedReferences(“primo”,Context.MODE\u PRIVATE);
primoo=primo.getString(“primoS”,即“”);
SharedReferences organo=GetSharedReferences(“oregano”,Context.MODE\u PRIVATE);
oregano=organo.getString(“oreganoS”,即“”);
SharedReferences pizzaMush=getSharedReferences(“pizzaMush”,Context.MODE\u PRIVATE);
pizzaMushS=pizzaMush.getString(“pizzamuss”,即“);
SharedReferences cheesePizza=getSharedReferences(“Pizzacese”,Context.MODE_PRIVATE);
pizzaChesse=cheesePizza.getString(“pizzacheses”,即“);
SharedReferences peproni=getSharedReferences(“peproni”,Context.MODE\u PRIVATE);
peproni=peproni.getString(“peproniS”,“peproniS”);
SharedReferences forSeason=GetSharedReferences(“四季”,Context.MODE\u PRIVATE);
fourSeasons=forSeason.getString(“fourSeasons”和“”);
SharedReferences意大利语PIZ=GetSharedReferences(“意大利语”,Context.MODE_PRIVATE);
意大利语pi=意大利语piz.getString(“意大利语”,“意大利语”);
SharedReferences hotPiz=GetSharedReferences(“热狗”,Context.MODE\u PRIVATE);
hotDog=hotPiz.getString(“hotDogS”,即“);
值=新的ArrayList();
添加(chickenBlanche);
value.add(费城语);
添加(蘑菇);
值。添加(超级);
value.add(primoo);
添加(牛至);
添加(比萨酱);
添加(比萨饼);
添加(pepproni);
添加(四个季节);
值。添加(意大利语pi);
添加(热狗);
布尔retval=chickenBlanche.isEmpty();
如果(retval==true){
textView.setVisibility(View.GONE);
}否则{
textView.setVisibility(View.VISIBLE);
}
布尔retval1=philadelphiaCheese.isEmpty();
如果(retval1==true){
textView.setVisibility(View.GONE);
}否则{
textView.setVisibility(View.VISIBLE);
}
ArrayAdapter=新的ArrayAdapter(此,R.layout.row_项,R.id.quantityId,值);
低压设置适配器(适配器);
在Xml文件夹中,我想将listview放在滚动视图中,但设计也不能像我所希望的那样工作 我想把列表视图放在滚动视图里面,还有很多其他的功能,比如文本视图和编辑文本 这是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>


我认为此代码的80%与您的问题无关。请创建一个演示您的问题的示例。不赞成懒惰地复制整个代码,而不是只复制相关部分。
    if (TextUtils.isEmpty(chickenBlanche)) {
        textView.setVisibility( View.GONE );
    } else {
        textView.setVisibility( View.VISIBLE );
    }


    if (TextUtils.isEmpty(philadelphiaCheese)) {
        textView.setVisibility( View.GONE );
    } else {
        textView.setVisibility( View.VISIBLE );
    }