Note that there are some explanatory texts on larger screens.

plurals
  1. PONot going to next activity when clicking on item in listview.
    primarykey
    data
    text
    <p>I am new to android, using sqlite to insert data in database, and use these data on custom list view. The problem occurs when I edit the data with edit button in next activity show the row string but, in every row edit but show the data of 1st row string.. by image u can esily understand: <img src="https://i.stack.imgur.com/LEQxa.jpg" alt="enter image description here"></p> <p>I want the row name in new activity page while i click on edit.. delete row when i press delete .. help me..</p> <p>editlist java file</p> <pre><code>public class EditLIST extends Activity { private AndroidSQLite mySQLiteAdapter ; final static String EXTRA_MESSAGE = "edit.list.message"; public void onClick (View view) { Intent intent = new Intent (this,display.class); TextView textView=(TextView) findViewById(R.id.textView1); String message=textView.getText().toString(); //data.putString("thetext",text); intent.putExtra(EXTRA_MESSAGE,message); startActivity(intent); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_list); ListView listContent = (ListView)findViewById(R.id.listView1); mySQLiteAdapter = new AndroidSQLite(this); mySQLiteAdapter.openToWrite(); mySQLiteAdapter.deleteAll(); mySQLiteAdapter.insert("umesh"); mySQLiteAdapter.insert("kalpesh"); mySQLiteAdapter.insert("manish"); mySQLiteAdapter.close(); mySQLiteAdapter = new AndroidSQLite(this); mySQLiteAdapter.openToRead(); Cursor cursor = mySQLiteAdapter.queueAll(); startManagingCursor(cursor); String[] from = new String[]{AndroidSQLite.KEY_FNAME}; int[] to = new int[]{R.id.textView1}; SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.button, cursor, from, to); listContent.setAdapter(cursorAdapter); } } </code></pre> <p>AndroidSQLite.java file</p> <p>package edit.list;</p> <pre><code>import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteDatabase.CursorFactory; public class AndroidSQLite { public static final String MYDATABASE_NAME = "abncd"; public static final String MYDATABASE_TABLE = "zxc"; public static final int MYDATABASE_VERSION = 1; public static final String KEY_ID = "_id"; public static final String KEY_FNAME = "FNAME"; //create table MY_DATABASE (ID integer primary key, Content text not null); private static final String SCRIPT_CREATE_DATABASE = "create table " + MYDATABASE_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_FNAME + " text not null);"; private SQLiteHelper sqLiteHelper; private SQLiteDatabase sqLiteDatabase; private Context context; public AndroidSQLite(Context c){ context = c; } public AndroidSQLite openToRead() throws android.database.SQLException { sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION); sqLiteDatabase = sqLiteHelper.getReadableDatabase(); return this; } public AndroidSQLite openToWrite() throws android.database.SQLException { sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION); sqLiteDatabase = sqLiteHelper.getWritableDatabase(); return this; } public void close(){ sqLiteHelper.close(); } public long insert(String fname){ ContentValues contentValues = new ContentValues(); contentValues.put(KEY_FNAME, fname); return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues); } public int deleteAll(){ return sqLiteDatabase.delete(MYDATABASE_TABLE, null, null); } public Cursor queueAll(){ String[] columns = new String[]{KEY_ID, KEY_FNAME}; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, null); return cursor; } public class SQLiteHelper extends SQLiteOpenHelper { public SQLiteHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(SCRIPT_CREATE_DATABASE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } } } </code></pre> <p>display.java</p> <pre><code>public class display extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.display); // Get the message from the intent Intent intent = getIntent(); String message = intent.getStringExtra(EditLIST.EXTRA_MESSAGE); // Create the text view EditText editText = new EditText(this); editText.setTextSize(40); editText.setText(message); // Set the text view as the activity layout setContentView(editText); } public boolean onCreateOptionsMenu (Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity_edit_list,menu); return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload