public class HomepageActivity extends ActionBarActivity {
protected List<ParseObject> mStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
Parse.initialize(this, "dcAMNT7HVOmOw0JDMelkg5UDr388O3xSgICiSK3N", "1aHIAldsUScxlbkWGkoyvHoHWM9YEtpTb6QIijrb");
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// show user the homepage status
ParseQuery<ParseObject> query = ParseQuery.getQuery("Status");
query.whereEqualTo("playerName", "Dan Stemkoski");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> status, ParseException e) {
if (e == null) {
//success
mStatus = status;
StatusAdapter adapter = new StatusAdapter(getListView().getContext(),mStatus);
setListadapter(adapter);
} else {
//there was a problem, Alert user
}
}
});
我被困了,因为我需要一个列表活动,我需要使用List适配器,但我使用的是我的HomepageActiviy扩展ActionBarActivity。唯一可行的方法是,如果我将扩展名更改为List活动,但是当我按下s4上的左键时,我的操作栏上的设置将不会仅显示在按钮的顶部。
答案 0 :(得分:1)
为什么会使事情变得复杂,您可以将其保留extends ActionBarActivity
并在xml布局文件中使用ListView
小部件。听起来很简单。
另外:您不能使用getListView
和setListadapter
,除非您正在延长ListActivity
,在您的情况下,您无法继续
提示:
http://developer.android.com/guide/topics/ui/layout/listview.html
或只是google与listview相关的任何内容
答案 1 :(得分:0)
也许这会有所帮助
public class HomepageActivity extends ActionBarActivity {
private ListView lv; // Add a reference to your listview
protected List<ParseObject> mStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
lv = (ListView) findViewById(R.id.list); // Initialize your listview by pointing it to the correct listview in the layout file
Parse.initialize(this, "dcAMNT7HVOmOw0JDMelkg5UDr388O3xSgICiSK3N", "1aHIAldsUScxlbkWGkoyvHoHWM9YEtpTb6QIijrb");
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// show user the homepage status
ParseQuery<ParseObject> query = ParseQuery.getQuery("Status");
query.whereEqualTo("playerName", "Dan Stemkoski");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> status, ParseException e) {
if (e == null) {
//success
mStatus = status;
StatusAdapter adapter = new StatusAdapter(HomepageActivity.this ,mStatus); // Use the activity's context as the first parameter
lv.setAdapter(adapter); // Populate you listview here
} else {
//there was a problem, Alert user
}
}
});
确保activity_homepage布局中的<ListView>
标记具有这样的id属性
android:id="@+id/list"
一切顺利:)