• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Productivity App(Help)

So to learn android development I've decided to create a simple productivity app. I've decided to start with a calendar. I have it where when you select a date it displays that with a text block. What I am trying to do now is to have it so you can create in event(appointment, upcoming birthday,etc) I've looked every where but people are giving mixed answers and some of them are old. Any ideas on how I can do this and if it can be done with the built in Calendarview?
 
Sorry I have no experience of any of them, just providing some resources for you to look into.
 
So what if I change it up and have the events be shown in a list view and highlighted on the calendarview. Is that something I can do or no
 
Using a ListView to display the dates would work.
I'm surprised at the limited functionality of the standard CalendarView. All it appears to do is allow you to select dates.
 
Yeah its weird. Not sure why google wont allow you to add events to it. I figured the ListView way would probably be better. Can I make it so when you click on a date in the CalendarView it will take you to that event in the listview?
 
Yes that's possible, you can add a date listener callback to the CalendarView which will tell you when the selected date changed.
 
Ok so i've been looking around and found https://stackoverflow.com/questions/22144891/how-to-add-listview-items-on-button-click-using-adapter On the Activity part I am stuck at:

Code:
public void onItemClick(AdapterView<?> a, View v, int position,
                    long id) {

Here is my code:
Code:
package com.example.johnathan.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    EditText editText;
    EditText editText2;
    Button addButton;
    ListView listView;
    ArrayList<String> listItems;
    ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        editText = (EditText) findViewById(R.id.editText2);
        addButton = (Button) findViewById(R.id.addItem);
        listView = (ListView) findViewById(R.id.listView);
        listItems = new ArrayList<String>();
        listItems.add("First Item - added on Activity Create");
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listItems);
        listView.setAdapter(adapter);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listItems.add(editText.getText().toString());
                listItems.add(editText2.getText().toString());
                adapter.notifyDataSetChanged();
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                long id) {
                    Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_LONG)
                            .show();
                }
                }
            }
        });
}

Im not sure why it looks different when I am using the "OnItemClickListener"

Any help would be appreciated. Thanks
 
What do you mean by "looks different"? The only difference is the parameter names used in the method definition. It's functionally the same code.
 
I've uploaded a screenshot for you.
 

Attachments

  • Capture.PNG
    Capture.PNG
    12.4 KB · Views: 157
You have too many close brackets in this block

Code:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                long id) {
                    Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_LONG)
                            .show();
                }
                }
            }
        });

There are 3 "{" but 4 "}" Remove the one at line 9 above.
 
Post up your current code. I'll paste it into Android Studio and tell you what your compile problem is.
 
MainActivity.java
Code:
package com.example.johnathan.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    EditText editText;
    EditText editText2;
    Button addButton;
    ListView listView;
    ArrayList<String> listItems;
    ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        editText = (EditText) findViewById(R.id.editText2);
        addButton = (Button) findViewById(R.id.addItem);
        listView = (ListView) findViewById(R.id.listView);
        listItems = new ArrayList<String>();
        listItems.add("First Item - added on Activity Create");
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listItems);
        listView.setAdapter(adapter);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listItems.add(editText.getText().toString());
                listItems.add(editText2.getText().toString());
                adapter.notifyDataSetChanged();
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                long id) {
                    Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_LONG)
                            .show();
                }

            }
        });

    }

activity_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.johnathan.myapplication.MainActivity">

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        tools:layout_editor_absoluteY="43dp"
        tools:layout_editor_absoluteX="0dp" />

    <Button
        android:id="@+id/addItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="215dp"
        tools:layout_editor_absoluteY="106dp" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="294dp"
        android:layout_height="209dp"
        tools:layout_editor_absoluteX="9dp"
        tools:layout_editor_absoluteY="187dp" />

</android.support.constraint.ConstraintLayout>
_main.xml
 
I corrected the syntax errors. Study the differences between your original code, and understand why it didn't work. Parentheses must match up.

Code:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    EditText editText;
    EditText editText2;
    Button addButton;
    ListView listView;
    ArrayList<String> listItems;
    ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        editText = (EditText) findViewById(R.id.editText2);
        addButton = (Button) findViewById(R.id.addItem);
        listView = (ListView) findViewById(R.id.listView);
        listItems = new ArrayList<String>();
        listItems.add("First Item - added on Activity Create");
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listItems);
        listView.setAdapter(adapter);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listItems.add(editText.getText().toString());
                listItems.add(editText2.getText().toString());
                adapter.notifyDataSetChanged();
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_LONG)
                        .show();
            }

        });

    }
}
 
Back
Top Bottom