Answer the question
In order to leave comments, you need to log in
How to extract data from the parse server and arrange it in a list view so that all people can see it?
I have an application where there is registration, you log in with your log and password, then go to the activity, fill in something in the line and transfer it to the server, this information is saved and only I can see it, you need to see everything in a separate activity, something like creating a post in VK
is an activity where you fill it out and send it to the server
public class TodoActivity extends Activity implements OnItemClickListener {
private EditText mTaskInput;
private ListView mListView;
private TaskAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todo);
Parse.initialize(this, "BOcZtetcc86ChvdBZRDCxJuKtufhq4l159kzpZtF", "n6uX0b6fae8ARqI2WL2oGEpgSF1jK3fGCj2Y3k5X");
ParseAnalytics.trackAppOpened(getIntent());
ParseObject.registerSubclass(Task.class);
ParseUser currentUser = ParseUser.getCurrentUser();
if(currentUser == null){
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
mAdapter = new TaskAdapter(this, new ArrayList<Task>());
mTaskInput = (EditText) findViewById(R.id.task_input);
mListView = (ListView) findViewById(R.id.task_list);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
updateData();
}
public void updateData(){
ParseQuery<Task> query = ParseQuery.getQuery(Task.class);
query.whereEqualTo("user", ParseUser.getCurrentUser());
query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
query.findInBackground(new FindCallback<Task>() {
@Override
public void done(List<Task> tasks, ParseException error) {
if(tasks != null){
mAdapter.clear();
for (int i = 0; i < tasks.size(); i++) {
mAdapter.add(tasks.get(i));
}
}
}
});
}
public void createTask(View v) {
if (mTaskInput.getText().length() > 0){
Task t = new Task();
t.setACL(new ParseACL(ParseUser.getCurrentUser()));
t.setUser(ParseUser.getCurrentUser());
t.setDescription(mTaskInput.getText().toString());
t.setCompleted(false);
t.saveEventually();
mAdapter.insert(t, 0);
mTaskInput.setText("");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.todo, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_logout:
ParseUser.logOut();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
return true;
}
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Task task = mAdapter.getItem(position);
TextView taskDescription = (TextView) view.findViewById(R.id.task_description);
task.setCompleted(!task.isCompleted());
if(task.isCompleted()){
taskDescription.setPaintFlags(taskDescription.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}else{
taskDescription.setPaintFlags(taskDescription.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
task.saveEventually();
}
}
public class TaskAdapter extends ArrayAdapter<Task> {
private Context mContext;
private List<Task> mTasks;
public TaskAdapter(Context context, List<Task> objects) {
super(context, R.layout.task_row_item, objects);
this.mContext = context;
this.mTasks = objects;
}
public TaskAdapter(Context context, int resource) {
super(context, resource);
}
public View getView(int position, View convertView, ViewGroup parent){
if(convertView == null){
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
convertView = mLayoutInflater.inflate(R.layout.task_row_item, null);
}
Task task = mTasks.get(position);
TextView descriptionView = (TextView) convertView.findViewById(R.id.task_description);
descriptionView.setText(task.getDescription());
if(task.isCompleted()){
descriptionView.setPaintFlags(descriptionView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}else{
descriptionView.setPaintFlags(descriptionView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
return convertView;
}
}
@ParseClassName("Task")
public class Task extends ParseObject{
public Task(){
}
public boolean isCompleted(){
return getBoolean("completed");
}
public void setCompleted(boolean complete){
put("completed", complete);
}
public String getDescription(){
return getString("description");
}
public void setDescription(String description){
put("description", description);
}
public void setUser(ParseUser currentUser) {
put("user", currentUser);
}
public void getTask(Task task){
put("Task", task);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question