ListActivity - Functionality

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby euromaster » Sun Jun 22, 2008 8:40 am

bloodcarter wrote:That's cool, but how to display some data from ArrayAdapter into my own layout, not predefined one?


instead of Android.R.layout.simplelistitem1 you can use R.layout.<name of layout file contained in reslayouts>
euromaster
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jun 16, 2008 10:37 pm

Top

Dialog and ListView possible?

Postby bornmw » Thu Dec 25, 2008 9:25 pm

Is it possible to put ListView on a Dialog?
bornmw
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 25, 2008 9:23 pm

Postby Spyvingen » Sat Jan 16, 2010 11:50 pm

Sorry if im kinda stupid :)

But i cant get it to work.

Done like this.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 if (c != null) {
  3.  
  4.                         String[] mStrings;
  5.  
  6.                         do {
  7.  
  8.                                 String SidNamn = c.getString(Column1);
  9.  
  10.                                 String SidAdress = c.getString(Column2);
  11.  
  12.                                 String data = "Sidnamn : " + SidNamn +"\nSid Adress : "+SidAdress;
  13.  
  14.                                 mStrings = new String[]{data};
  15.  
  16.                         }while(c.moveToNext());
  17.  
  18.                         this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, mStrings));
  19.  
  20.                 }    
  21.  
  22.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


But i get error on setListAdaptor it want me to create it as a new function.

I have imported the same as u and tryed ctrl+shift+O in eclipse (auto import) but it dont work either.


Why do i get this error?

Btw great guide just me who is a bit retard :)

Edit //
Btw the "c" is my cursor to the data from my database.

Edit no. 2 //
I have tryed the code straight in a new project to (copy paste) dont work there either.
If its any importance i have selected sdk for 1.5 when i created my projekt is that wrong
Spyvingen <-- relly nooby started yesterday :)
Spyvingen
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Jan 16, 2010 11:45 pm

Re: ListActivity - Functionality

Postby ajaypatelaj » Mon Apr 18, 2011 1:29 pm

Store parsed xml data to sqlite ? Android

I want to store the data which is shown by setListAdapter to sqlite .. how ca i ?? please help me

XML File http://p-xr.com/xml

Code: Select all
package com.pxr.tutorial.xmltest;

import java.util.ArrayList;
import java.util.HashMap;

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

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class Main extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listplaceholder);
       
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
     
       
        String xml = XMLfunctions.getXML();
        Document doc = XMLfunctions.XMLfromString(xml);
               
        int numResults = XMLfunctions.numResults(doc);
       
        if((numResults <= 0)){
           Toast.makeText(Main.this, "Geen resultaten gevonden", Toast.LENGTH_LONG).show(); 
           finish();
        }
               
      NodeList nodes = doc.getElementsByTagName("result");
               
      for (int i = 0; i < nodes.getLength(); i++) {                     
         HashMap<String, String> map = new HashMap<String, String>();   
         
         Element e = (Element)nodes.item(i);
         map.put("id", XMLfunctions.getValue(e, "id"));
           map.put("name", "Naam:" + XMLfunctions.getValue(e, "name"));
           map.put("Score", "Score: " + XMLfunctions.getValue(e, "score"));
           
           mylist.add(map);         
      }      
       
        ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main,
                        new String[] { "id","name", "Score" },
                        new int[] {R.id.id, R.id.item_title, R.id.item_subtitle });
       
        setListAdapter(adapter);
       
       /* final ListView lv = getListView();
        lv.setTextFilterEnabled(true);   
        lv.setOnItemClickListener(new OnItemClickListener() {
           public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
              @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                 
              Toast.makeText(Main.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show();

         }
      });*/
    }
}
ajaypatelaj
Junior Developer
Junior Developer
 
Posts: 22
Joined: Mon Apr 04, 2011 12:54 pm

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests