Skip to content

Commit

Permalink
final version of ex2
Browse files Browse the repository at this point in the history
  • Loading branch information
giltal1 committed Mar 16, 2015
1 parent 53f53f9 commit 8ce866f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import java.util.List;
import java.util.zip.Inflater;

/**
* Created by Gil on 14/03/2015.
*/
public class ItemAdapter extends ArrayAdapter<String> {

public ItemAdapter(Context context, int resource, List<String> tasks) {
Expand All @@ -29,7 +26,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
tv.setTextColor(color);
tv.setTextSize(30);
String item = getItem(position);
tv.setText(item.toString());
tv.setText(item);
return view;
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,72 @@
package il.ac.huji.todolistmanager;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class TodoListManagerActivity extends ActionBarActivity {

final Context context = this;
private List<String> items;
private ArrayAdapter<String> adapter;
ListView itemsList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todo_list_manager);

//ListView
ListView itemsList = (ListView) findViewById(R.id.items_list);
itemsList = (ListView) findViewById(R.id.items_list);
items = new ArrayList<String>();
adapter = new ItemAdapter(this, android.R.layout.simple_list_item_1, items);
itemsList.setAdapter(adapter);
}
itemsList.setOnItemLongClickListener(new OnItemLongClickListener() {

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);

//Custom Dialog Title
TextView title = new TextView(context);
title.setText(itemsList.getItemAtPosition(position).toString());
title.setBackgroundColor(Color.GRAY);
title.setPadding(10, 30, 10, 30);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.WHITE);
title.setTextSize(20);
builder.setCustomTitle(title);

//Delete Button
builder.setPositiveButton("Delete Item", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
items.remove(position);
adapter.notifyDataSetChanged();
}
});

builder.show();
return true;
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand All @@ -55,7 +92,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

public boolean addItem() {
EditText text = (EditText) findViewById(R.id.edit_new_item);
if (text == null) {
if (text.getText().toString().isEmpty()) {
return false;
}
String newItem = text.getText().toString();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/menu/menu_todo_list_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
android:orderInCategory="100"
app:showAsAction="never" />


</menu>

0 comments on commit 8ce866f

Please sign in to comment.