Note that there are some explanatory texts on larger screens.

plurals
  1. POError when click on the listview Android
    primarykey
    data
    text
    <p>im still new in android development.. i face a problem to develop searching function on my apps.. im using the code from this website <a href="http://www.mysamplecode.com/2011/11/android-searchview-using-sqlite-fts3.html" rel="nofollow">http://www.mysamplecode.com/2011/11/android-searchview-using-sqlite-fts3.html</a> </p> <p>and i eliminated a particular code that i'm don't want to use..especially "date" luckily,it got no errors n it works... but when i try to click on the listview showed,, my emulator gave a notice "Unfortunately TryandError has stop"</p> <p>when i check the logcat..it showed...</p> <p>at.com.example.tryanderror.SearchViewActivity$1.onClickItem(SearchViewActivity.java:137)</p> <p>here is my code from the original example given by the website, the main.xml i split out become this 2 xml.</p> <p>activity_search_view.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".SearchViewActivity" &gt; &lt;LinearLayout android:id="@+id/leftLayout" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content" android:paddingBottom="50dp"&gt; &lt;SearchView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/search" /&gt; &lt;ListView android:layout_width="fill_parent" android:id="@+id/list" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>rightlayout.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rightLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; </code></pre> <p>SearchViewActivity.java</p> <pre><code>package com.example.tryanderror; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SearchView; import android.widget.SimpleCursorAdapter; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; public class SearchViewActivity extends Activity implements SearchView.OnQueryTextListener, SearchView.OnCloseListener { private ListView mListView; private SearchView searchView; private CustomersDbAdapter mDbHelper; private TextView customerText; private TextView nameText; private TextView addressText; private TextView cityText; private TextView stateText; private TextView zipCodeText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_view); searchView = (SearchView) findViewById(R.id.search); searchView.setIconifiedByDefault(false); searchView.setOnQueryTextListener(this); searchView.setOnCloseListener(this); mListView = (ListView) findViewById(R.id.list); mDbHelper = new CustomersDbAdapter(this); mDbHelper.open(); //Clean all Customers mDbHelper.deleteAllCustomers(); //Add some Customer data as a sample mDbHelper.createCustomer("PIZZA1", "Pizza Hut", "1107 West Adams Boulevard", "", "Los Angeles", "CA", "90007"); mDbHelper.createCustomer("PIZZA2", "Pizza Hut", "1562 West Pico Boulevard", "", "Los Angeles", "CA", "90015"); mDbHelper.createCustomer("PIZZA3", "Pizza Hut", "718 South Los Angeles Street", "", "Los Angeles", "CA", "90014"); mDbHelper.createCustomer("PIZZA4", "Pizza Hut", "2542 West Temple Street", "", "Los Angeles", "CA", "90026"); mDbHelper.createCustomer("PIZZA5", "Pizza Hut", "4329 North Figueroa Street", "", "Los Angeles", "CA", "90065"); mDbHelper.createCustomer("PIZZA6", "Pizza Hut", "4351 South Central Avenue", "", "Los Angeles", "CA", "90011"); mDbHelper.createCustomer("SUB1", "Subway", "975 West Jefferson", "", "Los Angeles", "CA", "90007"); mDbHelper.createCustomer("SUB2", "Subway", "2805 South Figueroa Street", "", "Los Angeles", "CA", "90007"); mDbHelper.createCustomer("SUB3", "Subway", "198 South Vermont Avenue", "", "Los Angeles", "CA", "90004"); mDbHelper.createCustomer("SUB4", "Subway", "504 West Olympic Boulevard", "", "Los Angeles", "CA", "90015"); } @Override protected void onDestroy() { super.onDestroy(); if (mDbHelper != null) { mDbHelper.close(); } } public boolean onQueryTextChange(String newText) { showResults(newText + "*"); return false; } public boolean onQueryTextSubmit(String query) { showResults(query + "*"); return false; } public boolean onClose() { showResults(""); return false; } private void showResults(String query) { Cursor cursor = mDbHelper.searchCustomer((query != null ? query.toString() : "@@@@")); if (cursor == null) { // } else { // Specify the columns we want to display in the result String[] from = new String[] { CustomersDbAdapter.KEY_CUSTOMER, CustomersDbAdapter.KEY_NAME, CustomersDbAdapter.KEY_ADDRESS, CustomersDbAdapter.KEY_CITY, CustomersDbAdapter.KEY_STATE, CustomersDbAdapter.KEY_ZIP}; // Specify the Corresponding layout elements where we want the columns to go int[] to = new int[] { R.id.scustomer, R.id.sname, R.id.saddress, R.id.scity, R.id.sstate, R.id.szipCode}; // Create a simple cursor adapter for the definitions and apply them to the ListView SimpleCursorAdapter customers = new SimpleCursorAdapter(this,R.layout.customerresult, cursor, from, to); mListView.setAdapter(customers); // Define the on-click listener for the list items mListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // Get the cursor, positioned to the corresponding row in the result set Cursor cursor = (Cursor) mListView.getItemAtPosition(position); // Get the state's capital from this row in the database. String customer = cursor.getString(cursor.getColumnIndexOrThrow("customer")); String name = cursor.getString(cursor.getColumnIndexOrThrow("name")); String address = cursor.getString(cursor.getColumnIndexOrThrow("address")); String city = cursor.getString(cursor.getColumnIndexOrThrow("city")); String state = cursor.getString(cursor.getColumnIndexOrThrow("state")); String zipCode = cursor.getString(cursor.getColumnIndexOrThrow("zipCode")); //Check if the Layout already exists LinearLayout customerLayout = (LinearLayout)findViewById(R.id.customerLayout); if(customerLayout == null){ //Inflate the Customer Information View LinearLayout mainLayout = (LinearLayout)findViewById(R.id.rightLayout); View customerInfo = getLayoutInflater().inflate(R.layout.customerinfo, mainLayout, false); mainLayout.addView(customerInfo); } //Get References to the TextViews customerText = (TextView) findViewById(R.id.customer); nameText = (TextView) findViewById(R.id.name); addressText = (TextView) findViewById(R.id.address); cityText = (TextView) findViewById(R.id.city); stateText = (TextView) findViewById(R.id.state); zipCodeText = (TextView) findViewById(R.id.zipCode); // Update the parent class's TextView customerText.setText(customer); nameText.setText(name); addressText.setText(address); cityText.setText(city); stateText.setText(state); zipCodeText.setText(zipCode); searchView.setQuery("",true); } }); } } } </code></pre> <p>i hope someone can help me solve this.. please.. thank you..</p>
    singulars
    1. This table or related slice is empty.
    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