Note that there are some explanatory texts on larger screens.

plurals
  1. POOnClick item dont work on SQLite DB populated to list view
    primarykey
    data
    text
    <p>I have tried to make this work, but it keeps redirecting me to the error page I created for the the webview activity.</p> <p>The app is like a book app, I created the db for the "Add to Fav" tab, when the Add to Fav is clicked, it adds the current webview page "id" and "title" to the db, I'm trying to do it so that when the bookmark'd listview is clicked, it opens the URL.</p> <p>The alert dialog works fine in the OnLongItemClick method. please check the below code</p> <pre><code>import java.util.ArrayList; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; public class GoToFav extends Activity { private GymsDbHelper mHelper; private SQLiteDatabase dataBase; private ArrayList&lt;String&gt; gymId = new ArrayList&lt;String&gt;(); private ArrayList&lt;String&gt; htitle = new ArrayList&lt;String&gt;(); private ListView gymList; private AlertDialog.Builder build; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.favpage); gymList = (ListView) findViewById(R.id.gymList); mHelper = new GymsDbHelper(this); gymList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { String name = htitle.get(position); if (name.equals("XXXXXX")) { Intent i = new Intent(GoToFav.this, WebViewActivity.class); i.putExtra("keyHTML", "file:///android_asset/gympage1.html"); startActivity(i); } else { Intent i = new Intent(getApplicationContext(), WebViewActivity.class); i.putExtra("keyHTML", "file:///android_asset/yerrorpage.html"); startActivity(i); } } }); // long click to delete data gymList.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, final int arg2, long arg3) { build = new AlertDialog.Builder(GoToFav.this); build.setTitle("Delete " + htitle.get(arg2)); build.setMessage("Do you want to delete ?"); build.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), htitle.get(arg2) + " is deleted.", Toast.LENGTH_LONG).show(); dataBase.delete( GymsDbHelper.TABLE_NAME, GymsDbHelper.KEY_ID + "=" + gymId.get(arg2), null); displayData(); dialog.cancel(); } }); build.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = build.create(); alert.show(); return true; } }); } @Override protected void onResume() { displayData(); super.onResume(); } /** * displays data from SQLite */ private void displayData() { dataBase = mHelper.getWritableDatabase(); Cursor mCursor = dataBase.rawQuery("SELECT * FROM " + GymsDbHelper.TABLE_NAME, null); gymId.clear(); htitle.clear(); if (mCursor.moveToFirst()) { do { gymId.add(mCursor.getString(mCursor .getColumnIndex(GymsDbHelper.KEY_ID))); htitle.add(mCursor.getString(mCursor .getColumnIndex(GymsDbHelper.KEY_HTITLE))); } while (mCursor.moveToNext()); } FavAdapter favadpt = new FavAdapter(GoToFav.this, gymId, htitle); gymList.setAdapter(favadpt); mCursor.close(); } } </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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