SHARE
TWEET

Untitled

a guest Sep 18th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.n.sqlitecruddemo;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5.  
  6. import android.content.Intent;
  7. import android.database.Cursor;
  8. import android.support.v4.widget.SimpleCursorAdapter;
  9. import android.view.Menu;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12. import android.widget.AdapterView;
  13. import android.widget.ListView;
  14. import android.widget.TextView;
  15.  
  16. public class SubjectListActivity extends AppCompatActivity {
  17.  
  18.    private DBManager mDBManager;
  19.  
  20.    private ListView mListView;
  21.  
  22.    private SimpleCursorAdapter mAdaper;
  23.  
  24.    final String[] from = new String[] { DatabaseHelper._ID,
  25.            DatabaseHelper.SUBJECT, DatabaseHelper.DESC };
  26.  
  27.    final int[] IDS = new int[] { R.id.id, R.id.title, R.id.desc };
  28.  
  29.    @Override
  30.    protected void onCreate(Bundle savedInstanceState) {
  31.        super.onCreate(savedInstanceState);
  32.  
  33.        setContentView(R.layout.fragment_subject_list);
  34.  
  35.        mDBManager = new DBManager(this);
  36.        mDBManager.open();
  37.        Cursor cursor = mDBManager.fetch();
  38.  
  39.        mListView = (ListView) findViewById(R.id.subject_list_view);
  40.        mListView.setEmptyView(findViewById(R.id.empty_view));
  41.  
  42.        mAdaper = new SimpleCursorAdapter(this, R.layout.activity_view_all_subject, cursor, from, IDS, 0);
  43.        mAdaper.notifyDataSetChanged();
  44.  
  45.        mListView.setAdapter(mAdaper);
  46.  
  47.        // OnCLickListiner For List Items
  48.        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  49.            @Override
  50.            public void onItemClick(AdapterView<?> parent, View view, int position, long viewId) {
  51.                TextView idTextView = (TextView) view.findViewById(R.id.id);
  52.                TextView titleTextView = (TextView) view.findViewById(R.id.title);
  53.                TextView descTextView = (TextView) view.findViewById(R.id.desc);
  54.  
  55.                String id = idTextView.getText().toString();
  56.                String title = titleTextView.getText().toString();
  57.                String desc = descTextView.getText().toString();
  58.  
  59.                Intent modify_intent = new Intent(getApplicationContext(), ModifySubjectActivity.class);
  60.                modify_intent.putExtra("name", title);
  61.                modify_intent.putExtra("desc", desc);
  62.                modify_intent.putExtra("id", id);
  63.  
  64.                startActivity(modify_intent);
  65.            }
  66.        });
  67.    }
  68.  
  69.    @Override
  70.    public boolean onCreateOptionsMenu(Menu menu) {
  71.        getMenuInflater().inflate(R.menu.main, menu);
  72.        return true;
  73.    }
  74.  
  75.    @Override
  76.    public boolean onOptionsItemSelected(MenuItem item) {
  77.  
  78.        int id = item.getItemId();
  79.        if (id == R.id.add_record) {
  80.  
  81.            Intent add_mem = new Intent(this, AddSubjectsActivity.class);
  82.            startActivity(add_mem);
  83.  
  84.        }
  85.        return super.onOptionsItemSelected(item);
  86.    }
  87.  
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top