2. Example 2 – Display multi select checkboxes on the ListView using ArrayList. We will also save user selections in private preferences of the user and reload the same when application gets restarted.
3. Example 3 – Display multi select checkboxes on the ListView using Xml file and standard Android data adapters and list item layout. We will also save user selections in private preferences of the user and reload the same when application gets restarted.
4. Example 4 – Display multi select checkboxes on the ListView using Sqlite database and Android cursor data adapter. We will also save user selections in private preferences of the user and reload the same when application gets restarted.
5. Example 5 – Display multi select checkboxes on the ListView from Sqlite database using custom data Adapter and custom list item layout.
Lets jump into the first example.
Skill Assumptions:
You have configured your Android development environment on Eclipse or other tools
You know how to create a new Android project
Step 1 – Create a new Eclipse project
Step 2 - Add a default Activity named Start which will add main.xml under layout folder and Start.java under your namespace folder under src.
Step 3 – Copy paste following Xml on your main.xml file.
a href="http://www.mediafire.com/file/wtwz9r6ka9w464x/linearlayout%20xmlns.docx"
.
.
Downlaod the .Xml and Manifest Files by clicking this URL
This is Explanation of the Activity
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Start extends Activity {
private String[] lv_arr = {};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Prepare an Array list of todo items
ArrayList listTODO = PrepareList();
// Get a handle to the list view
ListView lv = (ListView) findViewById(R.id.ListView01);
// Bind the data with the list
lv_arr = (String[]) listTODO.toArray(new String[0]);
lv.setAdapter(new ArrayAdapter
android.R.layout.simple_list_item_1, lv_arr));
}
// The main ArrayList .
private ArrayList PrepareList() {
ArrayList todoItems = new ArrayList();
todoItems.add("Fill up Gasoline");
todoItems.add("Wash car");
todoItems.add("Dinner with friends");
todoItems.add("Watch Movie");
return todoItems;
}
}
.
ReplyDelete