我想将ListActivty更改为扩展操作栏的活动,代码如下,我遇到了许多问题,将其更改为适用于活动消耗操作栏的代码,代码也包含parse.com元素。
public class dash extends ListActivity {
private List<Note> posts;
private Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_dash);
posts = new ArrayList<Note>();
ArrayAdapter<Note> adapter = new ArrayAdapter<Note>(this,
R.layout.list_item_layout, posts);
setListAdapter(adapter);
refreshPostList();
}
@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {
Note note = posts.get(position);
intent = new Intent(this, list.class);
intent.putExtra("noteId", note.getId());
intent.putExtra("noteTitle", note.getTitle());
intent.putExtra("noteContent", note.getContent());
intent.putExtra("noteUri", note.getUri());
startActivity(intent);
}
private void refreshPostList() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
query.whereEqualTo("author", ParseUser.getCurrentUser());
setProgressBarIndeterminateVisibility(true);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> postList, ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// If there are results, update the list of posts
// and notify the adapter
posts.clear();
for (ParseObject post : postList) {
Note note = new Note(post.getObjectId(), post.getString("title"), post.getString("content"), post.getString("uri"));
posts.add(note);
}
((ArrayAdapter<Note>) getListAdapter()).notifyDataSetChanged();
} else {
Log.d(getClass().getSimpleName(), "Error: " + e.getMessage());
}
}
});
}
}
我无法更改
setListAdapter(adapter);
和
((ArrayAdapter<Note>) getListAdapter()).notifyDataSetChanged();
我在使用onListItemClick时也遇到了一些问题,将其放在更改后的位置
答案 0 :(得分:1)
您可以在列表视图中添加ID。然后你可以尝试这样的事情。
ListView listview = (ListView)findViewById(R.id.yourlistviewid)
listview.setAdapter(adapter)
和
((ArrayAdapter<Note>) listview.getAdapter()).notifyDataSetChanged()
和
listview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position,long arg3) {
}
});