Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. TextView txt;
  2. String value;
  3. Button btn;
  4. private ListView lv1;
  5. private AlertDialog alertDialog;
  6. Bundle bundle ;
  7. String item;
  8. private SimpleCursorAdapter adapter;
  9. private Cursor cursor;
  10. private ListDbAdapter db;
  11.  
  12. private static final int MENU_CREATE = Menu.FIRST;
  13. private static final int MENU_RENAME=Menu.FIRST+4;
  14. private static final int MENU_EDIT = Menu.FIRST + 2;
  15. private static final int MENU_SEND=Menu.FIRST+3;
  16. private static final int MENU_DELETE=Menu.FIRST+1;
  17.  
  18. public void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.list1);
  21.  
  22. lv1=(ListView)findViewById(R.id.list);
  23.  
  24. db=new ListDbAdapter(this);
  25. db.open();
  26. fillData();
  27. registerForContextMenu(lv1);
  28.  
  29. lv1.setOnItemClickListener(new OnItemClickListener()
  30. {
  31.  
  32. public void onItemClick(AdapterView<?> parent,View v,int position, long id)
  33. {
  34. Intent j= new Intent(IncercListe.this, Produse.class);
  35. Cursor c = (Cursor)parent.getAdapter().getItem(position);
  36.  
  37. j.putExtra("param1",c.getString(c.getColumnIndex(db.KEY_TITLE)));
  38. j.putExtra("param2", c.getString(c.getColumnIndex(db.KEY_ROWID)));
  39. startActivity(j);
  40. }
  41. });
  42.  
  43. /* Cursor c=db.fetchAll();
  44. if (c.moveToFirst())
  45. {
  46. do {
  47. DisplayTitle(c);
  48. } while (c.moveToNext());
  49. }*/
  50. }
  51. public void DisplayTitle(Cursor c){
  52. Toast.makeText(this,
  53. "id: " + c.getString(0) + "n" +
  54. "title: " + c.getString(1) + "n",
  55. Toast.LENGTH_LONG).show();
  56. }
  57. public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
  58. menu.setHeaderTitle("Choose ");
  59. menu.add(0, MENU_RENAME, 0, "Rename List");
  60. menu.add(0, MENU_EDIT, 0, "Edit List");
  61. menu.add(0, MENU_SEND, 0, "Send List");
  62. menu.add(0, MENU_DELETE, 0, "Delete List");
  63. }
  64.  
  65. @Override
  66. public boolean onContextItemSelected(MenuItem mitem) {
  67.  
  68. switch (mitem.getItemId()) {
  69. case MENU_RENAME:
  70. rename();
  71. return true;
  72.  
  73. case MENU_EDIT:
  74.  
  75. Intent j= new Intent(IncercListe.this, ADDSHOP.class);
  76. j.putExtra("param1",???);
  77. startActivityForResult(j,0);
  78. return true;
  79.  
  80. case MENU_SEND:
  81. return true;
  82.  
  83. case MENU_DELETE:
  84. AdapterContextMenuInfo info=(AdapterContextMenuInfo)mitem.getMenuInfo();
  85. db.delete(info.id);
  86. fillData();
  87. return true;
  88. default:
  89. return super.onContextItemSelected(mitem);
  90. }
  91. }
  92.  
  93.  
  94.  
  95. public boolean onCreateOptionsMenu(Menu menu) {
  96. menu.add(0, MENU_CREATE, 0, "New List");//.setIcon(R.drawable.quit);
  97. return true;
  98. }
  99. /* Handles item selections */
  100.  
  101. }
  102.  
  103. public void createlist() {
  104. alertDialog = new AlertDialog.Builder(this).create();
  105. alertDialog.setTitle("New List");
  106. alertDialog.setMessage("Enter name of new shopping list :");
  107.  
  108. final EditText edt=new EditText(this);
  109. alertDialog.setView(edt);
  110. alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  111. public void onClick(DialogInterface dialog, int which) {
  112. item =edt.getText().toString();
  113. if (!item.equals("")) db.create(item);
  114. fillData();
  115. return;
  116. }
  117. });
  118. alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
  119. public void onClick(DialogInterface dialog, int which) {
  120. dialog.cancel();
  121. return;
  122. }
  123. });
  124. alertDialog.show();
  125.  
  126. }
  127. public void rename() {
  128.  
  129. }
  130.  
  131. public void sendlist(){
  132. }
  133.  
  134. protected void onActivityResult(int requestCode, int resultCode, Intent intent){
  135. super.onActivityResult(requestCode, resultCode, intent);
  136. fillData();
  137. }
  138. private void fillData(){
  139. cursor=db.fetchAll();
  140. startManagingCursor(cursor);
  141.  
  142. adapter=new SimpleCursorAdapter(this,R.layout.textview,cursor,
  143. new String[] {ListDbAdapter.KEY_TITLE},new int[] {R.id.txt1});
  144. lv1.setAdapter(adapter);
  145. }
Add Comment
Please, Sign In to add comment