Android的列表视图不工作视图、列表、工作、Android

2023-09-07 01:23:38 作者:树红树绿

我是新来android开发,我只是了解列表视图和阵列适配器等。我已经在Android Studio中的一个项目,有多个活动,我有一个阵列适配器和一个列表视图,但我每次运行应用程序,并切换到具有列表视图中它的应用程序没有响应的活动,并将其关闭。我已经检查了code和它是一样的,在几个教程我已经看到了code。我认为它有什么做的多种活动,我有,有人可以帮我吗?

 公共类StoreActivity扩展ActionBarActivity {的String [] = storeList {船1,船舶2,船舶3};@覆盖保护无效的onCreate(捆绑savedInstanceState){    super.onCreate(savedInstanceState);    的setContentView(R.layout.activity_store);    ListView的店;    店内=(ListView控件)findViewById(R.id.list);    ArrayAdapter<串GT;适配器=新ArrayAdapter(这一点,R.layout.row_layout,storeList);    store.setAdapter(适配器);} 

解决方案

如果您正在使用ArrayAdapter为直接创建列表,您不能使用自己的列表项试试这个follwing code,而不是你的code

  ArrayAdapter<串GT;适配器=新ArrayAdapter(getApplicationContext(),android.R.layout.simple_list_item_1,的listItem); 
Android Studio 4.2 gradle视图不显示task

i am new to android development, and i just learnt about list views and array adapters etc. I have a project in android studio that has multiple activities and in one i have a array adapter and a list view, but every time i run the app and switch to the activity that has the list view in it the app does not respond and it closes. I have checked the code and it is the same as the code in the several tutorials i have seen. I think that it has something to do with the multiple activities i have, can someone help me?

public class StoreActivity extends ActionBarActivity {

String[] storeList = {"Ship 1", "Ship 2", "Ship 3"};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_store);

    ListView store;
    store = (ListView) findViewById(R.id.list);

    ArrayAdapter<String> adapter = new ArrayAdapter(this, R.layout.row_layout, storeList);
    store.setAdapter(adapter);
}

解决方案

If you are using ArrayAdapter as Direct create the list You cannot use your own list items Try this follwing code instead of your code

 ArrayAdapter<String> adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, listItem);