简体   繁体   English

为什么我的程序只显示我的数组之一<string>我的所有 hashmap 数据中的食物而不是实际值?</string>

[英]Why does my program only show one of my Array <String> Food in all of my hashmap data instead of the actual values?

package com.example.rhc_checklist;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.rhc_checklist.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by User on 2/28/2017.
 */

public class ListDataActivity extends AppCompatActivity {

private static final String TAG = "ListDataActivity";

DatabaseHelper mDatabaseHelper;

private ExpandableListView mListView;
private ExpandableListAdapter listAdapter;
private List<String> listDataHeader;
private LinkedHashMap<String, List<String>> listHash;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_layout);
    mListView = (ExpandableListView) findViewById(R.id.lvExp);
    initData();
    listAdapter = new ExpandableListAdapter(this, listDataHeader, listHash) {
    };
    mListView.setAdapter(listAdapter);
    mDatabaseHelper = new DatabaseHelper(this);

   populateListView();
}

private void initData() {
    String kioskTasks[] = {"Working Properly:", "Guests Waiting:"};
    String foodTasks[] = {"Aromas Lines long:", "Aromas Clean:", "Food Prep Areas Clean:",
            "Kitchen Staff Busy:", "Kitchen Clean:", "EDR Clean and Stocked:", 
 "Staff:Friendly/Helpful/Uniforms:"};
    String tableTasks[] = {"All Tables Being Played:", "Guests Having Fun:", 
  "Staff:Friendly/Helpful/Uniforms:"};
    String hotelTasks[] = {"Less Than 5 Rooms Left at South Tower:", "Less Than 5 Rooms Left at North 
   Tower:",
            "Staff:Friendly/Helpful/Uniforms", "Front Desk Agent Present:"};
    String casinoTasks[] = {"Slot Attendants Helping Guests:", "Beverage Servers Asking For Drinks:",
            "Soda Machine Stocked and Maintained:", "Casino Host Visible and Talking to Guests:", 
  "Slots Being Played/Fun:",
            "Ash Trays Being Emptied:", "Glasses Being Picked Up:", "Cage Lines:", "Security Available:",
            "Floor Feels Busy:", "Restrooms Clean and Stocked:", "Staff:Friendly/Helpful/Uniforms:",
            "Trash on Floor:", "Attendants Walking in Pairs:", "Masks Worn by Staff:", "Masks Worn by Guests:"};
    String cleanTeamTasks[] = {"Staff on Task:", "Following Proper Procedure: 1. Spray Cloth 2. Wipe Buttons 3. Wipe Screen 4. Wipe Chair:"};
    String travelersTasks[] = {"Truck Lot Full:", "Showers Utilized:", "Clean:", "RV Park Full:",
            "Staff:Friendly/Helpful/Uniforms:"};
    String parkTasks[] = {"Clean:", "Security Observed:", "Well Lit:"};
    String cstoreTasks[] = {"Staff:Friendly/Helpful/Uniforms:", "Clean/Organized:", "Pumps Working:",
            "Bathrooms Clean:", "Well Lit:"};
    String securityTasks[] = {"Anything Going On?:", "Ride Along with Lot Patrol:", "Staff Walking in Pairs:"};
    String equestrianTasks[] = {"Event:", "Attendance:", "Guests Enjoying Show:", "Impact on Casino Floor:"};
    String constructionTasks[] = {"Secure Access Points:", "Equipment/Tools Exposed/Unattended:",
            "Equipment Subject to Theft or Misuse:", "Fire Hazards/Trash/Chemicals:", "Trip Hazards",
            "Sharp or Low Hanging Objects:", "Adequate Signage:", "Adequate Lighting:"};
    String early = "Early Shift: ";
    String late = "Late Shift: ";
    listDataHeader = new ArrayList<>();
    listHash = new LinkedHashMap<>(500);
    listDataHeader.clear();
    listDataHeader.add("Kiosks");
    listDataHeader.add("Food and Beverage");
    listDataHeader.add("Table Games");
    listDataHeader.add("Hotels");
    listDataHeader.add("Casino Floor");
    listDataHeader.add("Clean Team");
    listDataHeader.add("Travelers Center");
    listDataHeader.add("Parking Lot");
    listDataHeader.add("C-Store");
    listDataHeader.add("Security");
    listDataHeader.add("Equestrian Center");
    listDataHeader.add("Construction Areas");

    List<String> Kiosks = new ArrayList<>();
    for (int i = 0; i < kioskTasks.length; i++){
        Kiosks.add(kioskTasks[i]);
    }
    List<String> Food = new ArrayList<>();
    for (int i = 0; i < foodTasks.length; i++){
        Food.add(foodTasks[i]);
    }
    List<String> Table = new ArrayList<>();
    for (int i = 0; i < tableTasks.length; i++){
        Table.add(tableTasks[i]);
    }
    List<String> Hotel= new ArrayList<>();
    for (int i = 0; i < hotelTasks.length; i++){
        Hotel.add(hotelTasks[i]);
    }
    List<String> Casino= new ArrayList<>();
    for (int i = 0; i < casinoTasks.length; i++){
        Casino.add(casinoTasks[i]);
    }
    List<String> Clean = new ArrayList<>();
    for (int i = 0; i < cleanTeamTasks.length; i++){
        Clean.add(cleanTeamTasks[i]);
    }
    List<String> Travelers = new ArrayList<>();
    for (int i = 0; i <travelersTasks.length; i++){
        Travelers.add(travelersTasks[i]);
    }
    List<String> Park= new ArrayList<>();
    for (int i = 0; i < parkTasks.length; i++){
        Park.add(parkTasks[i]);
    }
    List<String> CStore = new ArrayList<>();
    for (int i = 0; i < cstoreTasks.length; i++){
        CStore.add(cstoreTasks[i]);
    }
    List<String> Security= new ArrayList<>();
    for (int i = 0; i < securityTasks.length; i++){
        Security.add(securityTasks[i]);
    }
    List<String> Equestrian= new ArrayList<>();
    for (int i = 0; i < equestrianTasks.length; i++){
        Equestrian.add(equestrianTasks[i]);
    }
    List<String> Construction = new ArrayList<>();
    for (int i = 0; i < constructionTasks.length; i++){
        Construction.add(constructionTasks[i]);
    }

    listHash.put(listDataHeader.get(0), Kiosks);
    listHash.put(listDataHeader.get(1), Food);
    listHash.put(listDataHeader.get(2), Table);
    listHash.put(listDataHeader.get(3), Hotel);
    listHash.put(listDataHeader.get(4), Casino);
    listHash.put(listDataHeader.get(5), Clean);
    listHash.put(listDataHeader.get(6), Travelers);
    listHash.put(listDataHeader.get(7), Park);
    listHash.put(listDataHeader.get(8), CStore);
    listHash.put(listDataHeader.get(9), Security);
    listHash.put(listDataHeader.get(10), Equestrian);
    listHash.put(listDataHeader.get(11), Construction);
}[enter image description here][1]

Not allowed to embed images yet so https://i.stack.imgur.com/K5wig.png还不允许嵌入图像,所以https://i.stack.imgur.com/K5wig.png

This is a screenshot of the output on the android emulator.这是 android 仿真器上 output 的屏幕截图。 You can see that only the foodTasks are being shown on all categories.您可以看到所有类别中仅显示 foodTasks。 I can't seem to figure out why...我似乎无法弄清楚为什么...

From what I can tell the Lists are all populated properly I added code to make sure at one point and they all have the appropriate data in them.据我所知,列表都已正确填充,我添加了代码以确保在某一时刻它们都包含适当的数据。 They just aren't being added into the HashMap for some reason.由于某种原因,它们只是没有被添加到 HashMap 中。 In Fact for the Construction and Casino categories the app crashes and says they are null.事实上,对于建筑和赌场类别,应用程序崩溃并说它们是 null。

Edit: ExpandableListAdapter Class for more error checking.编辑:ExpandableListAdapter Class 进行更多错误检查。

package com.example.rhc_checklist;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import org.w3c.dom.Text;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listDataHeader;
private LinkedHashMap<String, List<String>> listHashMap;

public ExpandableListAdapter(Context context, List<String> listDataHeader, LinkedHashMap<String, List<String>> listHashMap) {
    this.context = context;
    this.listDataHeader = listDataHeader;
    this.listHashMap = listHashMap;
}
@Override
public int getGroupCount() {
    return listDataHeader.size();
}

@Override
public int getChildrenCount(int i) {
    return listHashMap.get(listDataHeader.get(i)).size();
}

@Override
public Object getGroup(int i) {
    return listDataHeader.get(i);
}

@Override
public Object getChild(int i, int i1) {
    return listHashMap.get(listDataHeader.get(i)).get(i1);
}

@Override
public long getGroupId(int i) {
    return i;
}

@Override
public long getChildId(int i, int i1) {
    return i1;
}

@Override
public boolean hasStableIds() {
    return false;
}

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
    String headerTitle = (String)getGroup(i);
    if(view == null) {
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.list_group, null);
    }
    TextView lblListHeader = (TextView)view.findViewById(R.id.lblListHeader);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    lblListHeader.setText(headerTitle);
    return view;
}

@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
    final String childText = (String)getChild(1,i1);
    if(view == null){
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.list_item, null);
    }
    TextView txtListChild = (TextView)view.findViewById(R.id.lblListItem);
    txtListChild.setText(childText);
    return view;
}

@Override
public boolean isChildSelectable(int i, int i1) {
    return true;
}
}

I had a typographical error in file ExpandableListAdapter.java at line 80.我在第 80 行的文件ExpandableListAdapter.java中有一个印刷错误。
I accidentally put我不小心放了

final String childText = (String)getChild(1,i1);

instead of代替

final String childText = (String)getChild(i,i1);

Thanks for all of your help guys.感谢您的所有帮助。 This is solved.这解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的程序只输出一个结果而不是五个? - Why does my program only outputs one result instead five? "<i>Why does my while loop only go through one name in the database, instead of all of them?<\/i>为什么我的 while 循环只遍历数据库中的一个名称,而不是所有名称?<\/b> <i>my program should sum values assigned to the same name<\/i>我的程序应该对分配给同名的值求和<\/b>" - Why does my while loop only go through one name in the database, instead of all of them? my program should sum values assigned to the same name 为什么我的哈希图 <Boolean,String> 只有两个条目? - Why does my Hashmap<Boolean,String> only have two entries? 为什么我的 XML 解析器只返回一个字符串,而不是多个? - Why does my XML parser only returns one string, instead of multiple ones? 为什么我的程序打印“ null”而不是字符串? - Why is my program printing “null” instead of the string? 为什么我的Android ListAdapter只显示一个项目? - Why does my Android ListAdapter only show one item? 在 Jframe 中,为什么我的“getScreenSize()”只显示为 19201080 而不是实际的 Jframe 边框大小? - In Jframe, why does my "getScreenSize()" only show as 19201080 and not the actual Jframe border size? 为什么我的程序读取的行数比实际少一行? 为什么我的数组只接收一个? - Why is my program reading one less line than there actually is? And why is my array taking in only ones? 为什么我的程序仅返回零? - Why does my program return zeros only? 为什么我的嵌套哈希图将所有值设置为同一事物? - Why is my nested hashmap setting all the values to the same thing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM