Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listview with checkbox problem

 
ghouse mohammed
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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
  • 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


 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic