Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>use following class , ListDataActivityInterv</p> <pre><code>package com.pranav.listviewdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; public class ListDataActivityInterv extends Activity{ private ListView lsInterventiiView = null; // private PacientiDB pacientiDB = null; //private PacientiAdapter adapter = null; // private ArrayList&lt;Interventii&gt; listInterventii = null; Button button ; String text = null; ListView lv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listviewinterventii); lv = (ListView) findViewById(R.id.listView1); //text = getIntent().getExtras().getString("Pacienti"); //TextView textView1 = (TextView) findViewById(R.id.textView2); // textView1.setText(text); button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(ListDataActivityInterv.this, ListViewMultipleSelectionActivity.class); startActivity(intent); finish(); } }); Bundle b = getIntent().getExtras(); if(b!=null &amp;&amp; b.containsKey("selectedItems")){ String[] resultArr = b.getStringArray("selectedItems"); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, resultArr); lv.setAdapter(adapter); } } } </code></pre> <p>this is ListViewMultipleSelectionActivity.</p> <pre><code>package com.pranav.listviewdemo; import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.SparseBooleanArray; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; public class ListViewMultipleSelectionActivity extends Activity implements OnClickListener { Button button; ListView listView; ArrayAdapter&lt;String&gt; adapter; public String text = null; //private PacientiDB pacientiDB = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maincheckinterv); //text = getIntent().getExtras().getString("Pacienti"); //TextView text1 = (TextView) findViewById(R.id.textViewListInter); //text1.setText(text); findViewsById(); String[] sports = new String[]{"Cricket","football","game1","chess"}; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_multiple_choice, sports); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setAdapter(adapter); button.setOnClickListener(this); } private void findViewsById() { listView = (ListView) findViewById(R.id.listView2); button = (Button) findViewById(R.id.button2); } public void onClick(View v) { //Interventii interventie = pacientiDB.getInterv(text); SparseBooleanArray checked = listView.getCheckedItemPositions(); ArrayList&lt;String&gt; selectedItems = new ArrayList&lt;String&gt;(); for (int i = 0; i &lt; checked.size(); i++) { int position = checked.keyAt(i); if (checked.valueAt(i)) selectedItems.add(adapter.getItem(position)); } String[] outputStrArr = new String[selectedItems.size()]; for (int i = 0; i &lt; selectedItems.size(); i++) { outputStrArr[i] = selectedItems.get(i); // interventie = new Interventii(); // interventie.setDenumire(selectedItems.get(i)); // pacientiDB.insertI(interventie); } Intent intent = new Intent(getApplicationContext(), ListDataActivityInterv.class); Bundle b = new Bundle(); b.putStringArray("selectedItems", outputStrArr); intent.putExtras(b); startActivity(intent); } } </code></pre> <p>layout :-listviewinterventii.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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /&gt; &lt;ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>layout:-maincheckinterv.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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /&gt; &lt;ListView android:id="@+id/listView2" android:layout_width="match_parent" android:layout_height="390dp" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>manifest</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pranav.listviewdemo" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.pranav.listviewdemo.ListDataActivityInterv" android:label="@string/app_name" android:launchMode="singleInstance" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.pranav.listviewdemo.ListViewMultipleSelectionActivity" android:label="@string/app_name" android:launchMode="singleInstance" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    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.
 

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