Thursday, 15 August 2013

listactivity having 2 items with sectionindexer

listactivity having 2 items with sectionindexer

Hi guys I developing Dictionary application in android. My problem is how
can I put sectionIndexer (A-Z) in ListActivity having 2 items. In
OnclickListener the choosing item will view the meaning in another class
(i solved it). I want guys to combine the ListActivity having 2 items
(items and sub-Items) having A-Z (in the right side) with my
OnClickListener.
MyList.class
'
public class MyList extends ListActivity {
public SQLiteDatabase database;
public static final String ROW_ID = "row_id";
public static final String DB_word = "DspeakDictionary";
public static Cursor crs = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<Map<String, String>> list = buildData();
String[] from = { "name", "purpose" };
int[] to = {R.id.tvNameMl,R.id.tvPurpose};
SimpleAdapter adapter = new SimpleAdapter(this, list,
R.layout.mylist, from, to);
setListAdapter(adapter);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
HashMap<?, ?> fullObject = (HashMap<?, ?>)o;
// Toast.makeText(this, "You have chosen the pen: " + " " +
fullObject.get("name"), Toast.LENGTH_LONG).show();
String getName = (String) fullObject.get("name");
DatabaseConnector db = new DatabaseConnector(this);
db.open();
database = MyList.this.openOrCreateDatabase(DB_word, MODE_PRIVATE,
null);
Cursor crs = database.query("dictionaryTable",new String [] {
"_id"}, "word=?",
new String[] { getName },null, null, "word");
// the id need a long type
while(crs.moveToNext()){
id = crs.getLong(crs.getColumnIndex("_id"));
}
Intent viewCon = new Intent(MyList.this, ViewWord.class);
viewCon.putExtra(ROW_ID, id);
startActivity(viewCon);
db.close();
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
DatabaseConnector db = new DatabaseConnector(this);
db.open();
database = MyList.this.openOrCreateDatabase(DB_word, MODE_PRIVATE, null);
crs = database.query("dictionaryTable", new String []
{"word","definition"}, null,
null, null, null, "word");
while(crs.moveToNext()){
String uword = crs.getString(crs.getColumnIndex("word"));
String udef= crs.getString(crs.getColumnIndex("definition"));
list.add(putData(uword, udef));
}
db.close();
return list;
}
private HashMap<String, String > putData(String name, String purpose) {
HashMap<String, String > item = new HashMap<String, String>();
item.put("name", name);
item.put("purpose", purpose);
return item;
}
`

No comments:

Post a Comment