Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old February 3rd, 2013, 11:30 PM   #1 (permalink)
Member
Thread Author (OP)
 
Join Date: Dec 2011
Location: chennai
Posts: 158
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default GetAttribute value on android aml parser

I have to develop one android application.

Its performs the attribute value is display on listview...

This is my xml tags:

Quote:
<root>
<Categories>
<Category name="books">
<Articles>
<article articleid="170" title="Colour And Vibrancy Are Part Of Our DNA">
<Description>
Well-known interior designer
</Description>
I have used below code:
[HIGH]
public class MainActivity extends Activity {

String URL;
static String KEY_CATEGORY = "Categories";
ArrayList<HashMap<String, String>> songsList;
static final String KEY_PNAME = "Category";
static final String KEY_PRICE = "Description";
static final String KEY_THUMB_URL = "thumb_image";

ListAdapter adapter;

/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
songsList = new ArrayList<HashMap<String, String>>();
HorizontalListView list = (HorizontalListView) findViewById(R.id.listView1);

adapter = new ListAdapter(this, songsList);
list.setAdapter(adapter);

URL="http://webservices/new_feed_articls.xml";

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml);// getting DOM element

NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);

// looping through all song nodes &lt;song&gt;
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key =&gt; value
map.put( KEY_PNAME,((Element)nl.item(i)).getAttribute("name "));


map.put(KEY_PRICE, parser.getValue(e, KEY_PRICE));
map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

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


// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> map = songsList.get(position);
[/HIGH]

Here i have to run the app means the category name is displayed on listview.How can i get the attribute value ??? please help me.

I got the below error:

Quote:
02-04 10:51:11.859: I/ActivityThread(2803): queueIdle
02-04 10:51:11.859: V/ActivityThread(2803): Reporting idle of ActivityRecord{4a4a92d8 token=android.os.BinderProxy@4a4a8df8 {com.example.notch/com.example.notch.MainActivity}} finished=false
02-04 10:51:11.859: W/ActivityNative(2803): send ACTIVITY_IDLE_TRANSACTION
02-04 10:51:11.869: V/ActivityThread(2803): Reporting idle of ActivityRecord{4a4a92d8 token=android.os.BinderProxy@4a4a8df8 {com.example.notch/com.example.notch.MainActivity}} finished=false
02-04 10:51:11.869: W/ActivityNative(2803): send ACTIVITY_IDLE_TRANSACTION
02-04 10:51:11.869: I/ActivityThread(2803): queueIdle
02-04 10:51:11.919: W/System.err(2803): java.net.MalformedURLException: Protocol not found:
02-04 10:51:11.929: W/System.err(2803): at java.net.URL.<init>(URL.java:275)
02-04 10:51:11.929: W/System.err(2803): at java.net.URL.<init>(URL.java:159)
02-04 10:51:11.929: W/System.err(2803): at com.example.notch.ImageLoader.getBitmap(ImageLoade r.java:67)
02-04 10:51:11.929: W/System.err(2803): at com.example.notch.ImageLoader.access$0(ImageLoader .java:55)
02-04 10:51:11.929: W/System.err(2803): at com.example.notch.ImageLoader$PhotosLoader.run(Ima geLoader.java:132)
02-04 10:51:11.929: W/System.err(2803): at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:441)
02-04 10:51:11.929: W/System.err(2803): at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:305)
02-04 10:51:11.929: W/System.err(2803): at java.util.concurrent.FutureTask.run(FutureTask.jav a:137)
02-04 10:51:11.929: W/System.err(2803): at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1068)
02-04 10:51:11.929: W/System.err(2803): at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:561)
02-04 10:51:11.929: W/System.err(2803): at java.lang.Thread.run(Thread.java:1096)
02-04 10:51:40.579: W/IInputConnectionWrapper(2803): getExtractedText on inactive InputConnection
02-04 10:51:45.679: W/IInputConnectionWrapper(2803): getExtractedText on inactive InputConnection

krishnaveni is offline  
Reply With Quote
sponsored links
Old February 4th, 2013, 06:07 AM   #2 (permalink)
Member
Thread Author (OP)
 
Join Date: Dec 2011
Location: chennai
Posts: 158
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi.,

I got the o/p after change the below line:

Quote:
NodeList nl = doc.getElementsByTagName(KEY_PNAME);
Now i have to run the app means am getting the attribute value well...
krishnaveni is offline  
Reply With Quote
Reply
Tags
android, getattribute, java, xml parsing


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:08 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.