How to set Spinner selection by value, using CursorAdapter - position

I have a spinner I'm populating from the database. I want to choose which item from the list is selected by default. I need to find out what item in the list (CursorAdapter) has the value "Default Away" and set that to the selected value.
Spinner away_team_spinner = (Spinner)findViewById(R.id.away_team_spinner);
DatabaseHelper db = new DatabaseHelper(this);
Cursor team_list = db.getTeams(p_game_level);
startManagingCursor(team_list);
String[] team_name = new String[]{colTeamName};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, team_list, team_name, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
away_team_spinner.setAdapter(adapter);
//// HERE IS WHERE MY ERRORS START ////
Log.i("NEW_GAME","Before set arrayadapter");
CursorAdapter adapter_choose = (CursorAdapter)away_team_spinner.getAdapter();
Log.i("NEW_GAME","Before set setSelection");
away_team_spinner.setSelection(adapter_choose.getPosition("Default Away"));
This is the "solution" I found by searching on this web site. However, I cannot use "getPosition" with CursorAdapter object. I tried ArrayAdapter, but then the line after "Before set arrayadapter" comment errors with "android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter". What am I doing wrong? Thanks.

have you thought about running a for loop until you find the position then set the adapter position that way? ill draft up some code then test it, i'm doing something similar
and well this just did the trick, enjoy!
int cpos = 0;
for(int i = 0; i < simpleCursorAdapter.getCount(); i++){
cursor.moveToPosition(i);
String temp = cursor.getString((your column index, an int));
if ( temp.contentEquals(yourString)){
Log.d("TAG", "Found match");
cpos = i;
break;
}
}
spinner.setSelection(cpos);

Related

how to use poi to find word2003`s table

i use org.apache.poi.poi version 3.17
i want to fine the inclined line in office word2003(doc) tables
for example
enter image description here
i used the XWPFTableRow function
cell.get(index).getCttc().getTcPr().getTcBorders();
to find where is the line in word2007 version (docx)
my code like this :
Rang range = hwpf.getRange();
TableIterator iterator = new TableIterator(range);
while(iterator.hasNext())
{
Table next = iterator.next();
for(int i = 0; i<next.numRows();i++)
{
TableRow row = next.getRow(i);
for(int j =0 ;j<row.numCells();j++)
{
TableCell cell = row.getCell(j);
//now i cant find likeness function to find the line in doc
}
}
}```
but i can`t find likeness function in HWPFDocument
so i need your help
thank you so much

EPPlus corrupt Excel file when having more than 65,530 rows

I'm running into an issue with EPPlus when there are more than 65,530 rows that have a column with a hyperlink. The example below is configured to create 65,530 rows. With this number it will create the Excel file correctly (not corrupt). Once you run it with anything over 65,530, the Excel file will be created but when you open it, Excel will report that is corrupt. Any ideas how to solve this issue?
try
{
int maxRowsToCreate = 65530; //-- no errors will be generated
//int maxRowsToCreate = 65531; //-- error will be generated. The Excel file will be created but will give an error when trying to open it.
string report = string.Format("D:\\temp\\hypelinkIssue-{0}.xlsx", maxRowsToCreate.ToString());
if (File.Exists(report))
{
File.Delete(report);
}
using (ExcelPackage pck = new ExcelPackage(new System.IO.FileInfo(report)))
{
//Add the Content sheet
var ws = pck.Workbook.Worksheets.Add("Catalog");
ws.View.ShowGridLines = true;
var namedStyle = pck.Workbook.Styles.CreateNamedStyle("HyperLink"); //This one is language dependent
namedStyle.Style.Font.UnderLine = true;
namedStyle.Style.Font.Color.SetColor(Color.Blue);
ws.Column(1).Width = 100;
int rowIndex = 0;
for (int i = 0; i < maxRowsToCreate; i++)
{
rowIndex += 1;
string fullFilePath = string.Format("D:\\temp\\{0}", Path.GetRandomFileName());
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new Uri(string.Format(#"file:///{0}", fullFilePath));
ws.Cells[rowIndex, 1].Value = fullFilePath;
}
pck.Save();
}
System.Diagnostics.Process.Start(report);
}
catch (Exception ex)
{
throw ex;
}
The issue occurs when using ".Hyperlink". If instead I use ".Formula" and populate it with the "=HYPERLINK" Excel formula, it works fine. I was able to create 250k records with unique hyperlink using this approach. I did not try more than 250k but hopefully it will work fine.
Thanks for pointing me in the right direction.
/*
This only works with LESS than 65,530 hyperlinks
*/
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new OfficeOpenXml.ExcelHyperLink(fullFilePath, ExcelHyperLink.UriSchemeFile);
ws.Cells[rowIndex, 1].Value = fullFilePath;
/*
This works with more that 65,530 hyperlinks
*/
string cellFormula = string.Format("=HYPERLINK(\"{0}\")", filePath);
ws.Cells[rowIndex, 1].Formula = cellFormula;
This is because Excel limits the amount of unique URLs in a file to 65,530. You should try to insert them as text, instead of a url.
For a possible solution, take a look at this answer.

Passing ArrayList<CustomObject> along with other parameters to another activity, getting Null from arraylist

Intent intent = getIntent();
Model_Class dataObj = (Model_Class) intent.getSerializableExtra("value");
dataObj.getPrice();
dataObj.get_product_name();
ArrayList<InputListModleClass> _inputList = dataObj.getInputsList();
for (int j = 0; j <_inputList.size(); j++) {
InputListModleClass itemsObj = new InputListModleClass();
Id = itemsObj.getInputId();
Lable = itemsObj.getInputLable();
}
I can get all values from intent, but I am getting null in Id and Lable. How can I resolve this issue.
You are reading from newly created object instead of element from the intent.
InputListModleClass itemsObj = new InputListModleClass();
Instead of this try:
InputListModleClass itemsObj = _inputList.get(j);
and then you should have id and label from intent.

Comparing excel value with console output using selenium web driver

I am storing excel values in 1st array and console output values in 2nd array. Then I am comparing excel value with console output one by one .I have debug code and it stores value proper in arrays. But it always print "FALSE" even if value matches true.
My latest code is given below :
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/?gfe_rd=cr&ei=1YaGVMutHcXN8gf39ID4Aw&gws_rd=ssl#q=what+is+software+testing");
java.util.List<WebElement> links = driver.findElements(By.tagName("h3"));
int sizecount = links.size();
System.out.println(sizecount);
//READING DATA FROM EXCEL FROM 1ST COLUMN
FileInputStream input = new FileInputStream("D:\\sel.xls");
int count=0;
HSSFWorkbook wb = new HSSFWorkbook(input);
HSSFSheet sh = wb.getSheet("sheet1");
String exceldata[] = new String[20];
for (int i=0;i<=sh.getLastRowNum();i++)
{
HSSFRow row = sh.getRow(i);
exceldata[i]= row.getCell(count).toString();
System.out.println(exceldata[i]);
}
String linkdata[] = new String[20];
for(int j=1;j<=links.size()-1;j++)
{
linkdata[j] = links.get(j).getText();
System.out.println(linkdata[j]);
}
for(int k=0;k<links.size()-1;k++)
{
if(exceldata==linkdata)
{
System.out.println("TRUE");
}
else
{
System.out.println("FALSE");
}
}
driver.close();
}
}
Note : I have tried with operator == and .equals both.
I've told you few issues in your program, you can modify your program according to that.
Issue 1
When you are storing the value in exceldata and linkdata array, you are taking different index, exceldata array is storing value from index 0 and linkdata is storing value from index 1, so you need to modify your program something like below:
for(int k=0;k<links.size()-1;k++){
if(exceldata[k].trim().equals(linkdata[k+1].trim())){
System.out.println("TRUE");
}else{
System.out.println("FALSE");
}
}
There was one more issue, I've already told you.
You are good to go now.

problem in Retrieving rich text box sharepoint

I need to retrieve values from a rich text box from a list.My code till now is this..
ArrayList arCategory=new ArrayList();
SPList myList = myWeb.Lists["PList"];
SPQuery myQuery = new SPQuery();
myQuery.Query = "<OrderBy><FieldRef Name='ProgramID' Ascending="False"/></OrderBy>;
SPListItemCollection myItemCol = myList.GetItems(myQuery);
foreach (SPListItem myItem in myItemCol)
{
string strCatTxt = (string)myItem["Category"];-->
//Category is the multiline rich text column
arCategory.Add(strCatTxt);
}
for (int j = 0; j < arCategory.Count; j++)
{
Label lblCategory = new Label();
lblCategory.Text=arCategory[j].Tostring(); ---->Getting exception
}
The problem is not SharePoint here. In your code, you have lblCategory.Text=arCategory[j].Tostring();
If arCategory[j] is null, you get an exception when you call ToString() on it.
So basically you can fix it like this:
for (int j = 0; j < arCategory.Count; j++) {
if (arCategory[j]!=null){
Label lblCategory = new Label();
lblCategory.Text=arCategory[j].Tostring(); ---->Getting exception
}
}
EDIT:
Or, of course, you could add a <Where>... element in your query and read only values from the items which have Category different from null. This will also make your query execute faster!

Resources