ListView显示空白

时间:2017-12-12 16:46:00

标签: android listview

尝试在屏幕上显示状态名称

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String [] statesOfIndia ={"Andaman and Nicobar Islands","Andhra Pradesh","Arunachal Pradesh","Assam","Bihar","Chandigarh","Chhattisgarh","Dadra and Nagar Haveli","Daman and Diu","Delhi","Goa","Gujarat","Haryana","Himachal Pradesh","Jammu and Kashmir","Jharkhand","Karnataka","Kerala","Lakshadweep","Madhya Pradesh","Maharashtra","Manipur","Meghalaya","Mizoram","Nagaland","Orissa","Pondicherry","Punjab","Rajasthan","Sikkim","Tamil Nadu","Telangana","Tripura","Uttaranchal","Uttar Pradesh","West Bengal"};

    ArrayList arrayList = new ArrayList(Arrays.asList(statesOfIndia));

    ListView listView = (ListView)findViewById(R.id.myListViewID);

    ArrayAdapter arrayAdapter = new ArrayAdapter(getApplicationContext(),android.R.layout.simple_list_item_1,arrayList);
    listView.setAdapter(arrayAdapter);

    }
}

**预期结果:**屏幕应以Listview

的形式显示州名

**实际结果:**屏幕显示空白。(下面是相同的屏幕截图) enter image description here

0 个答案:

没有答案