wood burning stoves 2.0*
The moose likes Android and the fly likes listview with checkbox problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "listview with checkbox problem" Watch "listview with checkbox problem" New topic
Author

listview with checkbox problem

ghouse mohammed
Greenhorn

Joined: Nov 23, 2011
Posts: 15
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

Joined: Jan 30, 2010
Posts: 252
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

Joined: Nov 23, 2011
Posts: 15
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

Joined: Nov 08, 2003
Posts: 3476

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

Joined: Nov 23, 2011
Posts: 15
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
 
jQuery in Action, 2nd edition
 
subject: listview with checkbox problem
 
Similar Threads
How to Create two parallel listViews where each list view contains a text and a icon
Hashmap in android
reference a string array defined in external resources in custom listview
Customized chekclist list view
Problem geeting value in JSP after type casting Gurus Please help me