Could anyone please explain how I can achieve the same from SQLite query in Java? The following is the code:
static final String[] AUTHORS = new String[] { "Roberto Bola–o","David Mitchell"};
private static final String[][] BOOKS =
new String[][] { "The Savage Detectives", "2666" },{ "Ghostwritten",
"number9dream", "Cloud Atlas","Black Swan Green",
"The Thousand Autumns of Jacob de Zoet" } };
This code is from the following class to implement sectioned gridview:Sectioned Gridview
Related
I have module where I need to list all the data in the recyclerview, I already create this recyclerview on my project however I got error it says that Change 2nd parameter of method player choices from String to String[]. So I already change what the error says. right now still got error incompatible types: String[] cannot be converted to String
Here is the array that I want to list on my recyclerview:
String[] chicken_choice_status = {"Test", "Test2", "Test", "Test2", "Test", "Test2"};
Recyclerview Adapter:
player_choices[] player_choices = new player_choices[] {
new player_choices("1",chicken_choice_status,3,4,5)
};
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
PlayerChoiceAdapter adapter = new PlayerChoiceAdapter(player_choices);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));
recyclerView.setAdapter(adapter);
Here is the error:
After updating the class of
private String[] bet_ratio;
String[] bet_ratio
public String[] get_bet_ratio() {
return bet_ratio;
}
public void setBetRation(String[] bet_ratio) {
this.bet_ratio = bet_ratio;
}
I'am now getting error of
Hope someone help me for this. Thanks
Check the player_choices class to determine the type of the bet_ratio field. It should be defined as:
String[] bet_ratio;
The type of the bet_ratio field should be changed from String to String[] --
String[] bet_ratio;
Is it possible to load a SimpleCursorAdapter from an Array of data i have made?
This is how a load my Array:
String[][] arrayStixoi = new String[countCategory][countCategory];
int i = 0;
while(ccget.moveToNext()){
String stixoi = ccget.getString(ccget.getColumnIndex("stixoi"));
String syggraf=ccget.getString(ccget.getColumnIndex("syggrafeas"));
String notes=ccget.getString(ccget.getColumnIndex("syggrafeas"));
String news=ccget.getString(ccget.getColumnIndex("syggrafeas"));
arrayStixoi[i][0] = Integer.toString(i);
arrayStixoi[i][1] = stixoi;
arrayStixoi[i][2] = syggraf;
arrayStixoi[i][3] = notes;
arrayStixoi[i][4] = news;
i++;
String _id=arrayStixoi[i][0]+1;
}
Now i want that Array: arrayStixoi to load a SimpleCursorAdapter and then add this adapter to a ListView.
Is this possible? and how?
Thank you in advance for your time.
In your code snippet you have
ccget.moveToNext()
I assume ccget is an instance of Cursor. With that, you can just instantiate a SimpleCursorAdapter using its default constructor:
new SimpleCursorAdapter(
this, R.layout.your_layout,
ccget,
from,
to,
flags)
Please refer to the official documentation.
I have a resource string array that I want to put into an ArrayList, however the datatype that comes back is a String array. The string[] cannot be directly cast to ArrayList w/o receiving the following error:
Cannot cast from String[] to ArrayList
How to I convert the String[] datatype to ArrayList?
Edit
I have an adapter whose constructor takes an ArrayList and a resource string-array that I want to populate it.
If you can make do with a List<String> (and not specifically an ArrayList<String>), you can use:
List<String> list = Arrays.asList(stringArray);
Otherwise, you can do this:
ArrayList<String> list = new ArrayList<String>(Arrays.asList(stringArray));
However, the latter is less efficient (in both time and object creation count) than the other suggested solutions. Its only benefit is that it keeps the code down to one line and is easy to comprehend at a glance.
public ArrayList<String> arrayToArrayList(String[] array){
ArrayList<String> arrayList = new ArrayList<String>(array.length);
for(String string : array){
arrayList.add(string);
}
return arrayList;
}
how about this
import java.util.Collections;
String[] myStringArray = new String[] {"foo", "bar", "baz"};
List myList = new ArrayList(myStringArray.length);
Collections.addAll(myList, myStringArray);
I'm using an expandable list view to display folders and files that are in my app. However, due to my app allowing user to add files, the list would be jumbled up. So, my intention is to set the sorted list (in names) as my child list.
I know that there is Arrays.sort and Collections.sort, but both the method are void, rather then returning the list.
So how do I do it ?
My list:
private File recordImageFolder = new File (Environment.getExternalStorageDirectory(),"/Record/Image");
private File recordSoundFolder = new File (Environment.getExternalStorageDirectory(),"/Record/Sound");
private String[] groups = { "Image", "Sound" };
private String[][] children = { recordImageFolder.list(), recordSoundFolder.list() };
Instead of initializing these field members in their declarations you could initialize them in the constructor or an init method, allowing you to use Arrays.sort(Object[]):
private File recordImageFolder;
private File recordSoundFolder;
private String[] groups;
private String[][] children;
public MyClass() {
recordImageFolder = new File (Environment.getExternalStorageDirectory(),"/Record/Image");
recordSoundFolder = new File (Environment.getExternalStorageDirectory(),"/Record/Sound");
String[] recordImages = recordImageFolder.list();
String[] recordSounds = recordSoundFolder.list();
Arrays.sort(recordImages);
Arrays.sort(recordSounds);
groups = new String[] { "Image", "Sound" };
children = new String[][] { recordImages, recordSounds };
}
Been playing around with Android and using various resources have come up with this list:
public class TestingList extends ListActivity {
private static final String ICON_KEY = "icon";
private static final String TITLE_KEY = "title";
private static final String DETAIL_KEY = "detail";
private static final int[] ICONS = new int[] { R.drawable.lista,
R.drawable.listb, R.drawable.listc, R.drawable.listd };
private static final String[] TITLES = new String[] { "List 1", "List 2",
"List 3", "List 4" };
private static final String[] DETAILS = new String[] {
"List 1 description, a little more text here please, just testing how it reacts to more.",
"List 2 description, a little more text here please, just testing how it reacts to more.",
"List 3 description, a little more text here please, just testing how it reacts to more.",
"List 4 description, a little more text here please, just testing how it reacts to more." };
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
for (int i = 0; i < ICONS.length; i++) {
rows.add(createListItemMap(ICONS[i], TITLES[i],
DETAILS[i]));
}
// set up SimpleAdapter for icon_detail_list_item
String[] fromKeys = new String[] { ICON_KEY, TITLE_KEY, DETAIL_KEY };
int[] toIds = new int[] { R.id.icon, R.id.text1, R.id.text2 };
setListAdapter(new SimpleAdapter(this, rows,
R.layout.icon_detail_list_item, fromKeys, toIds));
}
I'd like to some how add list separators to this list, what would the best way to get that done. The final list will have a lot more items, but I'd like named separators at certain points.
if you want to add a single divider that will be the same for each row than that is simple. you just call setDivider(Drawable) on your list and add the drawable that will represent your divider.
If you want to divide the list by categories like divider then things get more complicated.
#CommonsWare has a nice demo and a library of how to achieve this in his cwac-Merge project.
here is a link: Cwac
have a look at SeperatedListAdapter or android-section-list