Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting String from ArrayList
    text
    copied!<p>I am getting data from database and putting it into a array.Array contain CODE (int) and DESCRIPTION (String).Code is in the gridview and i want that if someone clicks on a code then realted description should be shown in a new activity.i have used OnItemclicklistener but dont know how to get only String from the array to show it on a new activity. "i want that the code from arraylist should be printed on first screen and when clicked description ll be printed in new activity as textview"</p> <pre><code> private void show_data() { final GridView gv = (GridView) findViewById(R.id.gridView); // final ListView listview = (ListView) findViewById(R.id.listView1); final Database_handler db = new Database_handler(this); Cursor cur = db.fetchAllData(); final ArrayList&lt;String&gt; array_list = new ArrayList&lt;String&gt;(); if (cur.moveToFirst()) { do { array_list.add(cur.getString(0)); array_list.add(cur.getString(1)); } while (cur.moveToNext()); } final StableArrayAdapter adapter = new StableArrayAdapter(this, android.R.layout.simple_list_item_1, array_list); // listview.setAdapter(adapter); gv.setAdapter(adapter); gv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { /*SOME CODE*/ } </code></pre> <p>This is Stablearrayadapter class</p> <pre><code> public class StableArrayAdapter extends ArrayAdapter&lt;String&gt; { HashMap&lt;String, Integer&gt; mIdMap = new HashMap&lt;String, Integer&gt;(); public StableArrayAdapter(Context context, int textViewResourceId, List&lt;String&gt; objects) { super(context, textViewResourceId, objects); for (int i = 0; i &lt; objects.size(); ++i) { mIdMap.put(objects.get(i), i); } } </code></pre> <p>XML class</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView_descrip" android:layout_alignParentLeft="true" android:layout_marginLeft="70dp" android:layout_alignParentTop="true" android:layout_marginTop="50dp"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>activty for description</p> <pre><code> public class desc_view extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //To change body of overridden methods use File | Settings | File Templates. setContentView(R.layout.desc_view); /* try { Intent recv = getIntent(); ArrayList&lt;String&gt; array_list_recvd = recv.getStringArrayListExtra("array_list2"); int intValue = recv.getIntExtra("intVariableName", 0); TextView tv = (TextView) findViewById(R.id.textView_descrip); tv.setText(array_list_recvd.get(intValue)); setContentView(tv); } catch (Exception e) { Log.d("Error Second :", e.toString()); }*/ } </code></pre> <p>}</p>
 

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