[android-developers] Re: Two listview

2012-02-27 Thread kalandar
hi..
Ok now i understood you have only one xml file. and this file contains
some sub category values. first you are collect the main category
values and
display that values in listview.
when the user clicks the list item this will open another activity
and has to show the sub category values of that particular clicked
list value.

i think this is your need..
i have the solution for this...

public class XMLSourseLoader {

Document doc;
public HashMapObject,Object main = new HashMapObject, Object();
public XMLSourseLoader(String filename)
{
     try {
         File fXmlFile = new File(filename);
         DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
         doc = dBuilder.parse(fXmlFile);
         doc.getDocumentElement().normalize();
          NodeList nList = doc.getElementsByTagName(maincatagory);
          System.out.println(nList.getLength());

          for(int i=0;inList.getLength();i++)
          {
        Element e1 = (Element)nList.item(i);
        System.out.println(getTagValue(title, e1));

        NodeList node1 = 
e1.getElementsByTagName(subcatagory);

//this is the sub category map
        HashMapObject,Object catagory = new 
HashMapObject,
Object();

        for(int j=0;jnode1.getLength();j++)
        {
        Element e2 = (Element)node1.item(j);
        System.out.println(
+getTagValue(subtitle, e2));

        catagory.put(getTagValue(subtitle, 
e2), books);
        }
        main.put(getTagValue(title, e1), catagory);
          }
     }
     catch(Exception e)
     {
     System.out.println(e.toString());
     }

  }

public HashMapObject,Object getMainMap()
{
return(main);
}

public String getTagValue(String sTag, Element eElement){
    NodeList nlList=
eElement.getElementsByTagName(sTag).item(0).getChildNodes();
    Node nValue = nlList.item(0);
    return nValue.getNodeValue();
 }

}

the model xml file is

main
maincatagory
title/title
subcatagory
subtitle/subtitle

/subcatagory
subcatagory
subtitle/subtitle

/subcatagory

/maincatagory

/main

i just store the HashMap object inside the HashMap.
it is pretty easy. i hope this will help you...
if you have any clarification let me know
let me know this helps you or not.

have a happy coding

On Feb 27, 12:20 pm, hazem omies hazem.om...@gmail.com wrote:
 Many thanks kalandar ,

 yes , as you mentioned at first the,,, second listview in another
 activity  that related to first see my xml :

 music
     item
         id.../id
         title./title
         Description.. /Description
  a1. /a1
 duration../duration
 duration2/duration2
 thumb_url../thumb_url
         shortcodeZ/shortcodeZ
 commandZ/commandZ

 /music

 that when click in item in the first listview the go to aother listview
 ,,,how i can make this listview ?

 thanks,,,







 On Mon, Feb 27, 2012 at 8:45 AM, kalandar kasimk...@gmail.com wrote:
  hi hazim omies.
       I understood your code. But still i didn't understand what is
  your need.
  If you want to pass the clicked HashMap  value to another activity
  means you can use this code

   Intent in = new Intent(getApplicationContext(),
  SingleMenuItemActivity.class);
    in.putExtra(mapvalue, map );

  map is the object name of your HashMap.

  or else you want to create another listview in the same activity means
  let me know the xml values.
  better explain your need clearly...

  regards
  kalandar

  On Feb 25, 6:09 am, hazem omies hazem.om...@gmail.com wrote:
   hi kalandar ,

   i make the first listview using HashMap but i cant make the seconed
   list because i need to pass value from one list to another related to
   one ,,,plz see my code below
   package test.packag;

   import java.io.InputStream;
   import java.util.ArrayList;
   import java.util.HashMap;

   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;

   import aljamal.packag.R;
   import aljamal.packag.XMLParser;
   import android.app.Activity;
   import android.content.Intent;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.AdapterView;

[android-developers] Re: Two listview

2012-02-26 Thread kalandar
hi hazim omies.
  I understood your code. But still i didn't understand what is
your need.
If you want to pass the clicked HashMap  value to another activity
means you can use this code

  Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
  in.putExtra(mapvalue, map );

map is the object name of your HashMap.

or else you want to create another listview in the same activity means
let me know the xml values.
better explain your need clearly...

regards
kalandar

On Feb 25, 6:09 am, hazem omies hazem.om...@gmail.com wrote:
 hi kalandar ,

 i make the first listview using HashMap but i cant make the seconed
 list because i need to pass value from one list to another related to
 one ,,,plz see my code below
 package test.packag;

 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;

 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;

 import aljamal.packag.R;
 import aljamal.packag.XMLParser;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.TextView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ListView;

 public class test extends Activity {
         // All static variables
         static final String URL = http://192.168.0.197/test.xml;;
         // XML node keys
         static final String KEY_SONG = song; // parent node
         static final String KEY_ID = id;
         static final String KEY_TITLE = title;
         static final String KEY_ARTIST = artist;
         static final String KEY_DURATION = duration;
         static final String KEY_DURATION2 = duration2;
         static final String KEY_A1 = a1;
         static final String KEY_THUMB_URL = thumb_url;
         static final String KEY_SCZ = shortcodeZ;
         static final String KEY_CMZ = commandZ;

 ListView list;
     LazyAdapter adapter;

         @Override
         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 setContentView(R.layout.main2);

                 ArrayListHashMapString, String songsList = new
 ArrayListHashMapString, String();

                 XMLParser parser = new XMLParser();
                 InputStream is= parser.getStream(URL); // getting XML
                 Document doc = parser.getDomElement(is); // getting DOM 
 element

                 NodeList nl = doc.getElementsByTagName(KEY_SONG);
                 // looping through all song nodes song
                 for (int i = 0; i  nl.getLength(); i++) {
                         // creating new HashMap
                         HashMapString, String map = new HashMapString, 
 String();
                         Element e = (Element) nl.item(i);
                         // adding each child node to HashMap key = value
                         map.put(KEY_ID, parser.getValue(e, KEY_ID));
                         map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
                         map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
                         map.put(KEY_DURATION, parser.getValue(e, 
 KEY_DURATION));
                         map.put(KEY_DURATION2, parser.getValue(e, 
 KEY_DURATION2));
                         map.put(KEY_THUMB_URL, parser.getValue(e, 
 KEY_THUMB_URL));
                         map.put(KEY_SCZ, parser.getValue(e, KEY_SCZ));
                         map.put(KEY_CMZ, parser.getValue(e, KEY_CMZ));
                         map.put(KEY_A1, parser.getValue(e, KEY_A1));

                         // adding HashList to ArrayList
                         songsList.add(map);
                 }

                 list=(ListView)findViewById(R.id.list);

                 // Getting adapter by passing xml data ArrayList
         adapter=new LazyAdapter(this, songsList);
         list.setAdapter(adapter);

         // Click event for single list row

         list.setOnItemClickListener(new OnItemClickListener() {

                         public void onItemClick(AdapterView? parent, View 
 view,
                                         int position, long id) {

                                 String title = ((TextView)
 view.findViewById(R.id.title)).getText().toString();
                                 String artist =((TextView)
 view.findViewById(R.id.artist)).getText().toString();
                                 String duration =((TextView)
 view.findViewById(R.id.duration)).getText().toString();
                                 String du2 =((TextView)
 view.findViewById(R.id.du2)).getText().toString();
                                 String A1 =((TextView)
 view.findViewById(R.id.A1)).getText().toString();
                                 String SCZ =((TextView)
 view.findViewById(R.id.SCZ)).getText().toString();
                                 String CMZ =((TextView)
 

Re: [android-developers] Re: Two listview

2012-02-26 Thread hazem omies
Many thanks kalandar ,

yes , as you mentioned at first the,,, second listview in another
activity  that related to first see my xml :

music
item
id.../id
title./title
Description.. /Description
 a1. /a1
duration../duration
duration2/duration2
thumb_url../thumb_url
shortcodeZ/shortcodeZ
commandZ/commandZ

/music



that when click in item in the first listview the go to aother listview
,,,how i can make this listview ?

thanks,,,







On Mon, Feb 27, 2012 at 8:45 AM, kalandar kasimk...@gmail.com wrote:

 hi hazim omies.
  I understood your code. But still i didn't understand what is
 your need.
 If you want to pass the clicked HashMap  value to another activity
 means you can use this code

  Intent in = new Intent(getApplicationContext(),
 SingleMenuItemActivity.class);
   in.putExtra(mapvalue, map );

 map is the object name of your HashMap.

 or else you want to create another listview in the same activity means
 let me know the xml values.
 better explain your need clearly...

 regards
 kalandar

 On Feb 25, 6:09 am, hazem omies hazem.om...@gmail.com wrote:
  hi kalandar ,
 
  i make the first listview using HashMap but i cant make the seconed
  list because i need to pass value from one list to another related to
  one ,,,plz see my code below
  package test.packag;
 
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.HashMap;
 
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
 
  import aljamal.packag.R;
  import aljamal.packag.XMLParser;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.TextView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListView;
 
  public class test extends Activity {
  // All static variables
  static final String URL = http://192.168.0.197/test.xml;;
  // XML node keys
  static final String KEY_SONG = song; // parent node
  static final String KEY_ID = id;
  static final String KEY_TITLE = title;
  static final String KEY_ARTIST = artist;
  static final String KEY_DURATION = duration;
  static final String KEY_DURATION2 = duration2;
  static final String KEY_A1 = a1;
  static final String KEY_THUMB_URL = thumb_url;
  static final String KEY_SCZ = shortcodeZ;
  static final String KEY_CMZ = commandZ;
 
  ListView list;
  LazyAdapter adapter;
 
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main2);
 
  ArrayListHashMapString, String songsList = new
  ArrayListHashMapString, String();
 
  XMLParser parser = new XMLParser();
  InputStream is= parser.getStream(URL); // getting XML
  Document doc = parser.getDomElement(is); // getting DOM
 element
 
  NodeList nl = doc.getElementsByTagName(KEY_SONG);
  // looping through all song nodes song
  for (int i = 0; i  nl.getLength(); i++) {
  // creating new HashMap
  HashMapString, String map = new
 HashMapString, String();
  Element e = (Element) nl.item(i);
  // adding each child node to HashMap key = value
  map.put(KEY_ID, parser.getValue(e, KEY_ID));
  map.put(KEY_TITLE, parser.getValue(e,
 KEY_TITLE));
  map.put(KEY_ARTIST, parser.getValue(e,
 KEY_ARTIST));
  map.put(KEY_DURATION, parser.getValue(e,
 KEY_DURATION));
  map.put(KEY_DURATION2, parser.getValue(e,
 KEY_DURATION2));
  map.put(KEY_THUMB_URL, parser.getValue(e,
 KEY_THUMB_URL));
  map.put(KEY_SCZ, parser.getValue(e, KEY_SCZ));
  map.put(KEY_CMZ, parser.getValue(e, KEY_CMZ));
  map.put(KEY_A1, parser.getValue(e, KEY_A1));
 
  // adding HashList to ArrayList
  songsList.add(map);
  }
 
  list=(ListView)findViewById(R.id.list);
 
  // Getting adapter by passing xml data ArrayList
  adapter=new LazyAdapter(this, songsList);
  list.setAdapter(adapter);
 
  // Click event for single list row
 
  list.setOnItemClickListener(new OnItemClickListener() {
 
  public void onItemClick(AdapterView? parent,
 View view,
  int position, long id) {
 
  String title = ((TextView)
  

[android-developers] Re: Two listview

2012-02-24 Thread hazem omies
hi kalandar ,

i make the first listview using HashMap but i cant make the seconed
list because i need to pass value from one list to another related to
one ,,,plz see my code below
package test.packag;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import aljamal.packag.R;
import aljamal.packag.XMLParser;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class test extends Activity {
// All static variables
static final String URL = http://192.168.0.197/test.xml;;
// XML node keys
static final String KEY_SONG = song; // parent node
static final String KEY_ID = id;
static final String KEY_TITLE = title;
static final String KEY_ARTIST = artist;
static final String KEY_DURATION = duration;
static final String KEY_DURATION2 = duration2;
static final String KEY_A1 = a1;
static final String KEY_THUMB_URL = thumb_url;
static final String KEY_SCZ = shortcodeZ;
static final String KEY_CMZ = commandZ;


ListView list;
LazyAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);


ArrayListHashMapString, String songsList = new
ArrayListHashMapString, String();

XMLParser parser = new XMLParser();
InputStream is= parser.getStream(URL); // getting XML
Document doc = parser.getDomElement(is); // getting DOM element

NodeList nl = doc.getElementsByTagName(KEY_SONG);
// looping through all song nodes song
for (int i = 0; i  nl.getLength(); i++) {
// creating new HashMap
HashMapString, String map = new HashMapString, 
String();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key = value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
map.put(KEY_DURATION2, parser.getValue(e, 
KEY_DURATION2));
map.put(KEY_THUMB_URL, parser.getValue(e, 
KEY_THUMB_URL));
map.put(KEY_SCZ, parser.getValue(e, KEY_SCZ));
map.put(KEY_CMZ, parser.getValue(e, KEY_CMZ));
map.put(KEY_A1, parser.getValue(e, KEY_A1));

// adding HashList to ArrayList
songsList.add(map);
}


list=(ListView)findViewById(R.id.list);

// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, songsList);
list.setAdapter(adapter);


// Click event for single list row

list.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView? parent, View 
view,
int position, long id) {

String title = ((TextView)
view.findViewById(R.id.title)).getText().toString();
String artist =((TextView)
view.findViewById(R.id.artist)).getText().toString();
String duration =((TextView)
view.findViewById(R.id.duration)).getText().toString();
String du2 =((TextView)
view.findViewById(R.id.du2)).getText().toString();
String A1 =((TextView)
view.findViewById(R.id.A1)).getText().toString();
String SCZ =((TextView)
view.findViewById(R.id.SCZ)).getText().toString();
String CMZ =((TextView)
view.findViewById(R.id.CMZ)).getText().toString();

Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);

in.putExtra(firstVariableToPass, Passing a 
string);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_ARTIST, artist);
in.putExtra(KEY_A1, A1);
in.putExtra(KEY_DURATION, duration);
in.putExtra(KEY_DURATION2, du2);
in.putExtra(KEY_SCZ, SCZ);
in.putExtra(KEY_CMZ, CMZ);

 

[android-developers] Re: Two listview

2012-02-23 Thread kalandar
hi
It is very easy. you can use java collection classes.
I think HashMap will help you to do this work.
If you explain your process clearly then i can say the solution



On Feb 23, 7:20 pm, hazem omies hazem.om...@gmail.com wrote:
 hi.

 i have xml file that read remotely from server and put the data in
 listview  i need a way that this lisview on click item pass this value
 to another related listview  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en