Is there a way to fill a listview in activity2 with info from a listview in activity1? - android-listview

Activity 1 sends the info I want to Activity 2:
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id)
{
// Get the cursor, positioned to the corresponding row in the result set
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
final int item_id = cursor.getInt(cursor.getColumnIndex(GamesDbAdapter.KEY_ROWID));
String item_cursus = cursor.getString(cursor.getColumnIndex(GamesDbAdapter.KEY_CURSUS));
String item_onderdeel = cursor.getString(cursor.getColumnIndex(GamesDbAdapter.KEY_ONDERDEEL));
String item_tijd = cursor.getString(cursor.getColumnIndex(GamesDbAdapter.KEY_TIJD));
String item_game = cursor.getString(cursor.getColumnIndex(GamesDbAdapter.KEY_GAME));
String item_web = cursor.getString(cursor.getColumnIndex(GamesDbAdapter.KEY_WEB));
Intent intent = new Intent(actGames_FRONT_ListViewCursorAdaptorActivity.this, actGames_ALL_ListViewCursorAdaptorActivity.class);
intent.putExtra("cursus", item_cursus);
intent.putExtra("id", item_id);
intent.putExtra("game", item_game);
startActivity(intent);
Toast done =
Toast.makeText(getApplicationContext(), item_game, Toast.LENGTH_LONG);
done.show();
}
});
In Activity2 I want to display "game" in another listview, but setText doesn't work with Listview.
game = (TextView)findViewById(R.id.game);
Intent iin= getIntent();
Bundle c = iin.getExtras();
if(c!=null)
{
String item_game =(String) c.get("game");
game.setText(item_game);
}
String game_list = getIntent().getExtras().getString("game");
This is the simplecursoradapter in activity2:
private void displayListView() {
Cursor cursor = dbHelper.fetchAllCursus();
// The desired columns to be bound
String[] cursus = new String[] {
GamesDbAdapter.KEY_CURSUS,
};
// the XML defined views which the data will be bound to
int[] to = new int[] {
R.id.front,
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(
this, R.layout.games_row_front,
cursor,
cursus,
to,
0);
ListView listView = (ListView) findViewById(R.id.listView1);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
And this is in my DBadapter:
public Cursor fetchGames(){
String[] args = {"********************" };
Cursor mCursor = mDb.query(SQLITE_TABLE, null,
"cursus = ?" , args, KEY_GAME, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
When I replace the *** with a static item from the database it works but I can't get it to work with the intent from the first activity. Is there a way to fill a listview with info from another listview in another activity?

Related

getting error : 'onCreateLoader(int, Bundle)' in clashes with 'onCreateLoader(int, Bundle)' in androidx.loader.app.LoaderManager.LoaderCallbacks'

I am making a fragment that uses content provider to get contacts from any phone using listview
#SuppressWarnings("ALL")
public abstract class fragment3 extends Fragment implements
LoaderManager.LoaderCallbacks<Cursor>,
AdapterView.OnItemClickListener, androidx.loader.app.LoaderManager.LoaderCallbacks<Cursor> {
**strong text**
private LifecycleOwner owner;
private RVAdapter myadapter;
private Object CursorLoader;
public fragment3() {
}
public Loader<Cursor> loader;
private Cursor cursor;
public abstract class LoaderManager{}
ListView contactsList;
long contactId;
String contactKey;
Uri contactUri;
SimpleCursorAdapter cursorAdapter;
private final static int[] TO_IDS = {
android.R.id.text1
};
// The column index for the _ID column
final int CONTACT_ID_INDEX = 0;
// The column index for the CONTACT_KEY column
final int CONTACT_KEY_INDEX = 1;
#Override
public void onCreate(Bundle savedInstanceState) {
// Always call the super method first
super.onCreate(savedInstanceState);
// Initializes the loader
getLoaderManager().initLoader(0, null, this);}
#SuppressLint("ResourceType")
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Set the item click listener to be the current fragment.
contactsList.setOnItemClickListener(this);
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
// Gets the ListView from the View list of the parent activity
contactsList =
(ListView) getActivity().findViewById(R.layout.list_view);
// Gets a CursorAdapter
cursorAdapter = new SimpleCursorAdapter(
getActivity(),
R.layout.list_item,
null,
FROM_COLUMNS, TO_IDS,
0);
// Sets the adapter for the ListView
contactsList.setAdapter(cursorAdapter);
getLoaderManager().initLoader(0, null, this);
}
// If non-null, this is the current filter the user has provided.
static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.CONTACT_STATUS,
ContactsContract.Contacts.PHOTO_ID,
};
// Called just before the Fragment displays its UI
#Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
/*
* Makes search string into pattern and
* stores it in the selection array
*/
selectionArgs[0] = "%" + searchString + "%";
// Starts the query
return new CursorLoader(
getActivity(),
ContactsContract.Contacts.CONTENT_URI,
PROJECTION,
SELECTION,
selectionArgs,
null
);
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
// Put the result Cursor in the adapter for the ListView
cursorAdapter.swapCursor(cursor);
}
// Defines the text expression
#SuppressLint("InlinedApi")
final String SELECTION =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY + " LIKE ?" :
ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?";
// Defines a variable for the search string
private String searchString;
// Defines the array to hold values that replace the ?
private String[] selectionArgs = {searchString};
/*
* Defines an array that contains column names to move from
* the Cursor to the ListView.
*/
#SuppressLint("InlinedApi")
private final static String[] FROM_COLUMNS = {
Build.VERSION.SDK_INT
>= Build.VERSION_CODES.HONEYCOMB ?
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY :
ContactsContract.Contacts.DISPLAY_NAME
};
#Override
public void onItemClick(
AdapterView<?> parent, View item, int position, long rowID) {
// Get the Cursor
//Cursor cursor = parent.getAdapter().getCursor();
Cursor c = ((CursorAdapter)((parent)).getAdapter()).getCursor();
// Move to the selected contact
cursor.moveToPosition(position);
// Get the _ID value
contactId = cursor.getLong(CONTACT_ID_INDEX);
// Get the selected LOOKUP KEY
contactKey = cursor.getString(CONTACT_KEY_INDEX);
// Create the contact's content Uri
String mContactKey = "";
contactUri = ContactsContract.Contacts.getLookupUri(contactId, mContactKey);
/*
* You can use contactUri as the content URI for retrieving
* the details for a contact.
*/
}
// A UI Fragment must inflate its View
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the fragment layout
return inflater.inflate(R.layout.fragment_fragment3,
container, false);
}
#SuppressLint("InlinedApi") final String[] PROJECTION =
{
ContactsContract.Contacts._ID,
ContactsContract.Contacts.LOOKUP_KEY,
Build.VERSION.SDK_INT
>= Build.VERSION_CODES.HONEYCOMB ?
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY :
ContactsContract.Contacts.DISPLAY_NAME
};
#Override
public void onLoaderReset(#NonNull androidx.loader.content.Loader<Cursor> loader) {
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
}
}

In iText 7 java how do you update Link text after it's already been added to the document

I am using iText7 to build a table of contents for my document. I know all the section names before I start, but don't know what the page numbers will be. My current process is to create a table on the first page and create all the Link objects with generic text "GO!". Then as I add sections I add through the link objects and update the text with the page numbers that I figured out as I created the document.
However, at the end, what gets written out for the link is "GO!", not the updated page number values I set as I was creating the rest of the document.
I did set the immediateFlush flag to false when I created the Document.
public class UpdateLinkTest {
PdfDocument pdfDocument = null;
List<Link>links = null;
Color hyperlinkColor = new DeviceRgb(0, 102, 204);
public static void main(String[] args) throws Exception {
List<String[]>notes = new ArrayList<>();
notes.add(new String[] {"me", "title", "this is my text" });
notes.add(new String[] {"me2", "title2", "this is my text 2" });
new UpdateLinkTest().exportPdf(notes, new File("./test2.pdf"));
}
public void exportPdf(List<String[]> notes, File selectedFile) throws Exception {
PdfWriter pdfWriter = new PdfWriter(selectedFile);
pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument, PageSize.A4, false);
// add the table of contents table
addSummaryTable(notes, document);
// add a page break
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
// add the body of the document
addNotesText(notes, document);
document.close();
}
private void addSummaryTable(List<String[]> notes, Document document) {
links = new ArrayList<>();
Table table = new Table(3);
float pageWidth = PageSize.A4.getWidth();
table.setWidth(pageWidth-document.getLeftMargin()*2);
// add header
addCell("Author", table, true);
addCell("Title", table, true);
addCell("Page", table, true);
int count = 0;
for (String[] note : notes) {
addCell(note[0], table, false);
addCell(note[1], table, false);
Link link = new Link("Go!", PdfAction.createGoTo(""+ (count+1)));
links.add(link);
addCell(link, hyperlinkColor, table, false);
count++;
}
document.add(table);
}
private void addNotesText(List<String[]> notes, Document document)
throws Exception {
int count = 0;
for (String[] note : notes) {
int numberOfPages = pdfDocument.getNumberOfPages();
Link link = links.get(count);
link.setText(""+(numberOfPages+1));
Paragraph noteText = new Paragraph(note[2]);
document.add(noteText);
noteText.setDestination(++count+"");
if (note != notes.get(notes.size()-1))
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
}
}
private static void addCell(String text, Table table, boolean b) {
Cell c1 = new Cell().add(new Paragraph(text));
table.addCell(c1);
}
private static void addCell(Link text, Color backgroundColor, Table table, boolean b) {
Cell c1 = new Cell().add(new Paragraph(text));
text.setUnderline();
text.setFontColor(backgroundColor);
table.addCell(c1);
}
}
Quite more work needs to be done compared to the code you have now because the changes to the elements don't take any effect once you've added them to the document. Immediate flush set to false allows you to relayout the elements, but that does not happen automatically. The way you calculate the current page the paragraph will be placed on (int numberOfPages = pdfDocument.getNumberOfPages();) is not bulletproof because in some cases pages might be added in advance, even if the content is not going to be placed on them immediately.
There is a very low level way to achieve your goal but with the recent version of iText (7.1.15) there is a simpler way as well, which still requires some work though. Basically your use case is very similar to target-counter concept in CSS, with page counter being the target one in your case. To support target counters in pdfHTML add-on we added new capabilities to our layout module which are possible to use directly as well.
To start off, we are going to tie our Link elements to the corresponding Paragraph elements that they will point to. We are going to do it with ID property in layout:
link.setProperty(Property.ID, String.valueOf(count));
noteText.setProperty(Property.ID, String.valueOf(count));
Next up, we are going to create custom renderers for our Link elements and Paragraph elements. Those custom renderers will interact with TargetCounterHandler which is the new capability in layout module I mentioned in the introduction. The idea is that during layout operation the paragraph will remember the page on which it was placed and then the corresponding link element (remember, link elements are connected to paragraph elements) will ask TargetCounterHandler during layout process of that link element which page the corresponding paragraph was planed on. So in a way, TargetCounterHandler is a connector.
Code for custom renderers:
private static class CustomParagraphRenderer extends ParagraphRenderer {
public CustomParagraphRenderer(Paragraph modelElement) {
super(modelElement);
}
#Override
public IRenderer getNextRenderer() {
return new CustomParagraphRenderer((Paragraph) modelElement);
}
#Override
public LayoutResult layout(LayoutContext layoutContext) {
LayoutResult result = super.layout(layoutContext);
TargetCounterHandler.addPageByID(this);
return result;
}
}
private static class CustomLinkRenderer extends LinkRenderer {
public CustomLinkRenderer(Link link) {
super(link);
}
#Override
public LayoutResult layout(LayoutContext layoutContext) {
Integer targetPageNumber = TargetCounterHandler.getPageByID(this, getProperty(Property.ID));
if (targetPageNumber != null) {
setText(String.valueOf(targetPageNumber));
}
return super.layout(layoutContext);
}
#Override
public IRenderer getNextRenderer() {
return new CustomLinkRenderer((Link) getModelElement());
}
}
Don't forget to assign the custom renderers to their elements:
link.setNextRenderer(new CustomLinkRenderer(link));
noteText.setNextRenderer(new CustomParagraphRenderer(noteText));
Now, the other thing we need to do it relayout. You already set immediateFlush to false and this is needed for relayout to work. Relayout is needed because on the first layout loop we will not know all the positions of the paragraphs, but we will already have placed the links on the pages by the time we know those positions. So we need the second pass to use the information about page numbers the paragraphs will reside on and set that information to the links.
Relayout is pretty straightforward - once you've put all the content you just need to call a single dedicated method:
// For now we have to prepare the handler for relayout manually, this is going to be improved
// in future iText versions
((DocumentRenderer)document.getRenderer()).getTargetCounterHandler().prepareHandlerToRelayout();
document.relayout();
One caveat is that for now you also need to subclass the DocumentRenderer since there is an additional operation that needs to be done that is not performed under the hood - propagation of the target counter handler to the root renderer we will be using for the second layout operation:
// For now we have to create a custom renderer for the root document to propagate the
// target counter handler to the renderer that will be used on the second layout process
// This is going to be improved in future iText versions
private static class CustomDocumentRenderer extends DocumentRenderer {
public CustomDocumentRenderer(Document document, boolean immediateFlush) {
super(document, immediateFlush);
}
#Override
public IRenderer getNextRenderer() {
CustomDocumentRenderer renderer = new CustomDocumentRenderer(document, immediateFlush);
renderer.targetCounterHandler = new TargetCounterHandler(targetCounterHandler);
return renderer;
}
}
document.setRenderer(new CustomDocumentRenderer(document, false));
And now we are done. Here is our visual result:
Complete code looks as follows:
public class UpdateLinkTest {
PdfDocument pdfDocument = null;
Color hyperlinkColor = new DeviceRgb(0, 102, 204);
public static void main(String[] args) throws Exception {
List<String[]> notes = new ArrayList<>();
notes.add(new String[] {"me", "title", "this is my text" });
notes.add(new String[] {"me2", "title2", "this is my text 2" });
new UpdateLinkTest().exportPdf(notes, new File("./test2.pdf"));
}
public void exportPdf(List<String[]> notes, File selectedFile) throws Exception {
PdfWriter pdfWriter = new PdfWriter(selectedFile);
pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument, PageSize.A4, false);
document.setRenderer(new CustomDocumentRenderer(document, false));
// add the table of contents table
addSummaryTable(notes, document);
// add a page break
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
// add the body of the document
addNotesText(notes, document);
// For now we have to prepare the handler for relayout manually, this is going to be improved
// in future iText versions
((DocumentRenderer)document.getRenderer()).getTargetCounterHandler().prepareHandlerToRelayout();
document.relayout();
document.close();
}
private void addSummaryTable(List<String[]> notes, Document document) {
Table table = new Table(3);
float pageWidth = PageSize.A4.getWidth();
table.setWidth(pageWidth-document.getLeftMargin()*2);
// add header
addCell("Author", table, true);
addCell("Title", table, true);
addCell("Page", table, true);
int count = 0;
for (String[] note : notes) {
addCell(note[0], table, false);
addCell(note[1], table, false);
Link link = new Link("Go!", PdfAction.createGoTo(""+ (count+1)));
link.setProperty(Property.ID, String.valueOf(count));
link.setNextRenderer(new CustomLinkRenderer(link));
addCell(link, hyperlinkColor, table, false);
count++;
}
document.add(table);
}
private void addNotesText(List<String[]> notes, Document document) {
int count = 0;
for (String[] note : notes) {
Paragraph noteText = new Paragraph(note[2]);
noteText.setProperty(Property.ID, String.valueOf(count));
noteText.setNextRenderer(new CustomParagraphRenderer(noteText));
document.add(noteText);
noteText.setDestination(++count+"");
if (note != notes.get(notes.size()-1))
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
}
}
private static void addCell(String text, Table table, boolean b) {
Cell c1 = new Cell().add(new Paragraph(text));
table.addCell(c1);
}
private static void addCell(Link text, Color backgroundColor, Table table, boolean b) {
Cell c1 = new Cell().add(new Paragraph(text));
text.setUnderline();
text.setFontColor(backgroundColor);
table.addCell(c1);
}
private static class CustomLinkRenderer extends LinkRenderer {
public CustomLinkRenderer(Link link) {
super(link);
}
#Override
public LayoutResult layout(LayoutContext layoutContext) {
Integer targetPageNumber = TargetCounterHandler.getPageByID(this, getProperty(Property.ID));
if (targetPageNumber != null) {
setText(String.valueOf(targetPageNumber));
}
return super.layout(layoutContext);
}
#Override
public IRenderer getNextRenderer() {
return new CustomLinkRenderer((Link) getModelElement());
}
}
private static class CustomParagraphRenderer extends ParagraphRenderer {
public CustomParagraphRenderer(Paragraph modelElement) {
super(modelElement);
}
#Override
public IRenderer getNextRenderer() {
return new CustomParagraphRenderer((Paragraph) modelElement);
}
#Override
public LayoutResult layout(LayoutContext layoutContext) {
LayoutResult result = super.layout(layoutContext);
TargetCounterHandler.addPageByID(this);
return result;
}
}
// For now we have to create a custom renderer for the root document to propagate the
// target counter handler to the renderer that will be used on the second layout process
// This is going to be improved in future iText versions
private static class CustomDocumentRenderer extends DocumentRenderer {
public CustomDocumentRenderer(Document document, boolean immediateFlush) {
super(document, immediateFlush);
}
#Override
public IRenderer getNextRenderer() {
CustomDocumentRenderer renderer = new CustomDocumentRenderer(document, immediateFlush);
renderer.targetCounterHandler = new TargetCounterHandler(targetCounterHandler);
return renderer;
}
}
}

How to write android junit test case of expandablelist child view?

I want write test case for ExpandableListView child view.
I have a 5 group of Expandable list view. Every group has individual child layout. So every time it would be child count is 1.
I want settext of AutoCompleteTextView for mAcTxtCarName using
TouchUtils.tapView(this, mAcTxtCarName);
sendKeys(KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_U);
But i could not sendkeys like this.
This is code which i am using.
In this code, at assertSame(view, expandedView); not found same.
public void testStartCheckListActivity() throws Exception {
// add monitor to check for the second activity
final ActivityMonitor monitor = getInstrumentation().addMonitor(
CheckListActivity.class.getName(), null, false);
// find button and click it
final Button btnNewCalibration = (Button) mMenuActivity
.findViewById(R.id.btn_new_calibration);
// TouchUtils handles the sync with the main thread internally
TouchUtils.clickView(this, btnNewCalibration);
// wait 2 seconds for the start of the activity
final CheckListActivity checkListActivity = (CheckListActivity) monitor
.waitForActivityWithTimeout(2000);
assertNotNull(checkListActivity);
/** **New Calibration** */
// add monitor to check for the second activity
final ActivityMonitor monitorNewCalibration = getInstrumentation().addMonitor(
NewCalibrationActivity.class.getName(), null, false);
// find button and click it
final Button btnCheckListNext = (Button) checkListActivity
.findViewById(R.id.btn_footer_done);
TouchUtils.clickView(this, btnCheckListNext);
// wait 2 seconds for the start of the activity
final NewCalibrationActivity newCalibrationActivity = (NewCalibrationActivity) monitorNewCalibration
.waitForActivityWithTimeout(2000);
assertNotNull(newCalibrationActivity);
/** we get list view */
final ExpandableListView expandableListView = (ExpandableListView) newCalibrationActivity
.findViewById(R.id.explist_newcalibration);
newCalibrationActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
expandableListView.requestFocus();
expandableListView.performItemClick(expandableListView, 2,
expandableListView.getItemIdAtPosition(2));
}
});
JunitUtils.waitTime(10);
// *******get last calibration or validation details for default
// display.**********
final PreferencesStorage preferncesStorage = new PreferencesStorage();
// New Calibration Details object from preference storage.
final NewCalibrationDetails calibrationDetails = preferncesStorage
.getNewCalibrationDetails(newCalibrationActivity);
final SQLAdapter adapter = new SQLAdapter(newCalibrationActivity);
adapter.open();
adapter.getLastCalibrationDetails(calibrationDetails);
adapter.close();
// **************************************************************************
if (expandableListView.isGroupExpanded(2)) {
Logger.d(tag, "$$$$$$$$$$$$$$$$$$$$$$$$$$$");
final LayoutInflater mLayoutInflater = (LayoutInflater) newCalibrationActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = mLayoutInflater.inflate(R.layout.items_newcalibration_child_3,
expandableListView, false);
// final View view = View.inflate(newCalibrationActivity,
// R.layout.items_newcalibration_child_3, null);
AutoCompleteTextView mAcTxtCarName = (AutoCompleteTextView) view
.findViewById(R.id.actxt_car_name);
AutoCompleteTextView mAcTxtModelNumber = (AutoCompleteTextView) view
.findViewById(R.id.actxt_model_number);
EditText mEdTxtLicencePlate1 = (EditText) view.findViewById(R.id.et_licence_plate_1);
EditText mEdTxtLicencePlate2 = (EditText) view.findViewById(R.id.et_licence_plate_2);
EditText mEdTxtLicencePlate3 = (EditText) view.findViewById(R.id.et_licence_plate_3);
AutoCompleteTextView mAcTxtOdometerValue = (AutoCompleteTextView) view
.findViewById(R.id.actxt_odometer_value);
AutoCompleteTextView mAcTxtReportingCode = (AutoCompleteTextView) view
.findViewById(R.id.actxt_reporting_code);
final NewCalibrationAdapter calibrationAdapter = new NewCalibrationAdapter(
newCalibrationActivity, calibrationDetails);
final View expandedView = calibrationAdapter.getChildView(2, 0, true, view,
expandableListView);
assertSame(view, expandedView);
mAcTxtCarName.requestFocus();
TouchUtils.tapView(this, mAcTxtCarName);
sendKeys(KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_U);
getInstrumentation().waitForIdleSync();
}
else {
Logger.e(tag, "##############", null);
}
}

statement and method to update sqlite database

I need your help please. I've spent way too much time on this and I can only update the database if I specify the id number.
Click listview item and send data to new activity for editing
Edit data and return to listview activity. Simple right. hmmm.
#Override
public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
Cursor cursor = (Cursor)listView.getItemAtPosition(position);
String title = cursor.getString(cursor.getColumnIndexOrThrow(MoviesDbAdapter.KEY_TITLE));
String barcode = cursor.getString(cursor.getColumnIndexOrThrow(MoviesDbAdapter.KEY_BARCODE));
String rowId = cursor.getString(cursor.getColumnIndexOrThrow(MoviesDbAdapter.KEY_ROWID));
Intent movieEdit = new Intent(getBaseContext(), MovieEdit.class);
Bundle bundle = new Bundle();
bundle.putString("rowId", rowId);
bundle.putString("title", title);
bundle.putString("barcode", barcode);
movieEdit.putExtras(bundle);
startActivity(movieEdit);
Receive the intent from the listview activity:
if (this.getIntent().getExtras() != null) {
Bundle bundle = this.getIntent().getExtras();
editTitle.setText(bundle.getString("title"));
editBarcode.setText(bundle.getString("barcode"));
editId.setText(bundle.getString("rowId"));
}
The statement activated by a button:
case R.id.buttonSave:
mDb.open();
ContentValues values = new ContentValues();
values.put(MoviesDbAdapter.KEY_TITLE, title);
values.put(MoviesDbAdapter.KEY_BARCODE, barcode);
mDb.updateTitle("=?", title, barcode);
mDb.close();
The method in the MovieDbAdapter:
public boolean updateTitle(long rowId, String title, String barcode)
{
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
args.put(KEY_BARCODE, barcode);
return mDb.update(SQLITE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
I know this has been done to death but no matter what I try I just can't update the database with the new data.
Hope you can help guys.
change your code to the following
case R.id.buttonSave:
mDb.open();
mDb.updateTitle(rowId, title, barcode);
mDb.close();

Display Field for select item in the list grid

Hello all
I am using smart gwt 2.2 on windows with mozilla browser.
I am using a list grid with two fields.
I set the editor type of second field to SelectItem.
In that select item I am rendering a grid.
For select item I set the value field and the display field.
But after the select any item from select item it is display value field.
I am also attaching the code for it.
code for grid
public void initializeGrid() {
ListGrid grid = new ListGrid();
setGridProperty(grid);
grid.setFields(getGridFields());
grid.setData(getGridData());
getSmartContainer().addChild(grid);
}
private static ListGridRecord[] getGridData() {
ListGridRecord record = new ListGridRecord();
record.setAttribute("id", "");
record.setAttribute("name", "");
ListGridRecord record1 = new ListGridRecord();
record1.setAttribute("id", "");
record1.setAttribute("name", "");
return new ListGridRecord[] { record, record1 };
}
private static void setGridProperty(ListGrid grid) {
grid.setWidth("90%");
grid.setHeight(125);
grid.setCanEdit(true);
grid.setEditEvent(ListGridEditEvent.CLICK);
grid.setEditByCell(true);
grid.setAlternateRecordStyles(true);
grid.setShowAllRecords(true);
}
private static ListGridField[] getGridFields() {
ListGridField field = new ListGridField("id");
FormItem item = new TextItem();
field.setEditorType(item);
ListGridField field1 = new ListGridField("name");
SelectItem item1 = new SelectItem("name");
setPropertyForSelectitem(item1);
DataSource dataSource = new DataSource();
dataSource.setClientOnly(true);
item1.setOptionDataSource(dataSource);
setDataForSelectItem(dataSource);
field1.setEditorType(item1);
return new ListGridField[] { field, field1 };
}
Code for select item
public static void setDataForSelectItem(DataSource dataSource) {
for (int i = 0; i < 2; i++) {
ListGridRecord record = new ListGridRecord();
record.setAttribute("id", "1");
record.setAttribute("name", "name" + i);
record.setAttribute("address", "address" + i);
dataSource.addData(record);
}
}
private static void setPropertyForSelectitem(SelectItem item) {
item.setPickListFields(getFieldsForSelectItem());
item.setWidth(150);
item.setValueField("id");
item.setDisplayField("name");
item.setPickListWidth(250);
}
private static ListGridField[] getFieldsForSelectItem() {
ListGridField idField = new ListGridField("id");
ListGridField nameField = new ListGridField("name");
ListGridField addField = new ListGridField("address");
return new ListGridField[] {idField,nameField,addField };
}
[/CODE]
After drawing this grid it is rendering value field for the select item, but i want to render the name (as it is the display field for the select item).
Same select item I used in the dynamic form but it is working well at that place, but for the grid it is not working well.
Please Help.
Thanks