package com.example.ramya.trailmix;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MenuActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
}
String options[] = {"SCHOOL","SHOPPING","RESTAURANT","CUSTOM"};
ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.activity_menu,options);
ListView listView = (ListView) findViewById(R.id.MenuList);
listView.setAdapter(adapter);
}
setAdapter()
尚未解决。当我尝试导入android.app.Activity
和android.view.Menu
时,该语句将被忽略。我是Android工作室的新手。我该怎么解决这个问题?我的目标是在此活动的视图中将选项[]显示为ListView
。
答案 0 :(得分:0)
将所有内容移至onCreate()
public class MenuActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
String options[] = {"SCHOOL","SHOPPING","RESTAURANT","CUSTOM"};
ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.activity_menu,options);
ListView listView = (ListView) findViewById(R.id.MenuList);
listView.setAdapter(adapter);
}
}