• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

listview with checkbox problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i am creating a listview with checkbox. if i define data in class itself it is working but i want to access the data from string.xml file and i am using the following code. please suggest me solution how to access it
public class ListTestActivity extends ListActivity {
/** Called when the activity is first created. */
String tag = "Events";
String[] presidents;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivity
presidents =getResources().getStringArray(R.array.presidents_array);
ArrayAdapter<Model> adapter = new InteractiveArrayAdapter(this,
getModel());
Log.d(tag," event");
setListAdapter(adapter);
}

private List<Model> getModel() {
Log.d(tag,"bht");
List<Model> list = new ArrayList<Model>();

list.add(get("Linux"));/// here i want to access the strings.xml file instead of this any suggestion
Log.d(tag,"bht1");
list.add(get("Windows7"));
list.add(get("Suse"));
list.add(get("Eclipse"));
list.add(get("Ubuntu"));
list.add(get("Solaris"));
list.add(get("Android"));
list.add(get("iPhone"));
// Initially select one of the items
list.get(1).setSelected(true);
Log.d(tag," event1");
return list;
}

private Model get(String s) {
Log.d(tag," event2");
return new Model(s);
}
}
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solution is very simple....

To retrieve String from string.xml you can use getText(R.string.<your string resource name>);

getText is method defined in Context class.

I hope I understood you question correctly.
 
ghouse mohammed
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Hardik Trivedi thanks for the replay and problem is solved . i have another doubt i am creating a custom listview with two checkboxes with a array adapter class with the following code i want to retrieve the checkbox name which i have selected how it can be done blow is the code i am using will you suggest me what i am doing wrong


 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would you please edit your posts and use "Code" tags to format your code? It is really hard to follow your code without formatting.
 
ghouse mohammed
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi as said earlier in my post i have a custom listview with a textview and two checkboxes in a single row how could i knoe which checkbox is checked please let me know.
and when i checked one box after i scrolldown and again see that both the checkboxes are being checked what i am doing wrong
 
reply
    Bookmark Topic Watch Topic
  • New Topic