How do I display two strings in one TableRow?

Kreizi

New Member
I'd like to have two strings - one for the hour and one for the minute - I'd like to display them next to each other so they display as 7:30 but as I have things now - I can only display 7 (I need help figuring out how to put the :30 on the same line)\[code\]<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="wrap_content"android:stretchColumns="1" android:layout_margin="5dp"><TableRow> <TextView style="@style/StyleLabel" android:text="@string/name_lbl"/> <TextView android:id="@+id/nameText" style="@style/StyleText"/> </TableRow> <TableRow> <TextView style="@style/StyleLabel" android:text="@string/cap_lbl"/> <TextView android:id="@+id/capText" style="@style/StyleText"/> </TableRow> <TableRow> <TextView style="@style/StyleLabel" android:text="Time Limit"/> <TextView android:id="@+id/codeText" style="@style/StyleText"/> </TableRow> <TableRow> <TextView style="@style/StyleLabel" android:text="Linked Users"/> <TextView android:id="@+id/codeText" style="@style/StyleText"/> </TableRow> <TableRow> <TextView style="@style/StyleLabel" android:text="@string/code_lbl"/> <TextView android:id="@+id/timeEdit" style="@style/StyleText"/> </TableRow></TableLayout>\[/code\]JAVA:\[code\]import android.app.Activity;import android.app.AlertDialog;import android.os.AsyncTask;import android.os.Bundle;import android.view.ViewGroup;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.FrameLayout;import android.widget.TimePicker;public class AddEditCountry extends Activity { private long rowID; private EditText nameEt; private EditText capEt; private EditText codeEt; private TimePicker timeEt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_country); nameEt = (EditText) findViewById(R.id.nameEdit); capEt = (EditText) findViewById(R.id.capEdit); codeEt = (EditText) findViewById(R.id.codeEdit); timeEt = (TimePicker) findViewById(R.id.timeEdit); Bundle extras = getIntent().getExtras(); if (extras != null) { rowID = extras.getLong("row_id"); nameEt.setText(extras.getString("name")); capEt.setText(extras.getString("cap")); codeEt.setText(extras.getString("code")); timeEt.setCurrentHour(extras.getInt("time")); } Button saveButton =(Button) findViewById(R.id.saveBtn); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (nameEt.getText().length() != 0) { AsyncTask<Object, Object, Object> saveContactTask = new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... params) { saveContact(); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; saveContactTask.execute((Object[]) null); } else { AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this); alert.setTitle(R.string.errorTitle); alert.setMessage(R.string.errorMessage); alert.setPositiveButton(R.string.errorButton, null); alert.show(); } } }); } private void saveContact() { DatabaseConnector dbConnector = new DatabaseConnector(this); if (getIntent().getExtras() == null) { dbConnector.insertContact(nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), codeEt.getText().toString()); } else { dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), /* Storing as String*/ codeEt.getText().toString()); } }}\[/code\]SOLUTION ATTEMPT #1\[code\]import android.app.Activity;import android.app.AlertDialog;import android.os.AsyncTask;import android.os.Bundle;import android.view.ViewGroup;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.FrameLayout;import android.widget.TimePicker;public class AddEditCountry extends Activity { private long rowID; private EditText nameEt; private EditText capEt; private EditText codeEt; private TimePicker timeEt; private TimePicker minEt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_country); nameEt = (EditText) findViewById(R.id.nameEdit); capEt = (EditText) findViewById(R.id.capEdit); codeEt = (EditText) findViewById(R.id.codeEdit); timeEt = (TimePicker) findViewById(R.id.timeEdit); minEt = (TimePicker) findViewById(R.id.minEdit); Bundle extras = getIntent().getExtras(); if (extras != null) { rowID = extras.getLong("row_id"); nameEt.setText(extras.getString("name")); capEt.setText(extras.getString("cap")); codeEt.setText(extras.getString("code")); timeEt.setText(extras.getString("time") + ":" + extras.getString("min")); } Button saveButton =(Button) findViewById(R.id.saveBtn); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (nameEt.getText().length() != 0) { AsyncTask<Object, Object, Object> saveContactTask = new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... params) { saveContact(); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; saveContactTask.execute((Object[]) null); } else { AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this); alert.setTitle(R.string.errorTitle); alert.setMessage(R.string.errorMessage); alert.setPositiveButton(R.string.errorButton, null); alert.show(); } } }); } private void saveContact() { DatabaseConnector dbConnector = new DatabaseConnector(this); if (getIntent().getExtras() == null) { dbConnector.insertContact(nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), codeEt.getText().toString()); } else { dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), /* Storing as String*/ codeEt.getText().toString()); } }}\[/code\]UPDATED SOURCE Attempt 2:\[code\]import android.app.Activity;import android.app.AlertDialog;import android.os.AsyncTask;import android.os.Bundle;import android.view.ViewGroup;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.FrameLayout;import android.widget.TimePicker;public class AddEditCountry extends Activity { private long rowID; private EditText nameEt; private EditText capEt; private EditText codeEt; private TimePicker timeEt; private TimePicker minEt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_country); nameEt = (EditText) findViewById(R.id.nameEdit); capEt = (EditText) findViewById(R.id.capEdit); codeEt = (EditText) findViewById(R.id.codeEdit); timeEt = (TimePicker) findViewById(R.id.timeEdit); // minEt = (TimePicker) findViewById(R.id.minEdit); Bundle extras = getIntent().getExtras(); if (extras != null) { rowID = extras.getLong("row_id"); nameEt.setText(extras.getString("name")); capEt.setText(extras.getString("cap")); codeEt.setText(extras.getString("code")); timeEt.setCurrentHour(extras.getString("time") + ":" + extras.getString("min")); minEt.setCurrentMinute(extras.getInt("min")); } Button saveButton =(Button) findViewById(R.id.saveBtn); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (nameEt.getText().length() != 0) { AsyncTask<Object, Object, Object> saveContactTask = new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... params) { saveContact(); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; saveContactTask.execute((Object[]) null); } else { AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this); alert.setTitle(R.string.errorTitle); alert.setMessage(R.string.errorMessage); alert.setPositiveButton(R.string.errorButton, null); alert.show(); } } }); } private void saveContact() { DatabaseConnector dbConnector = new DatabaseConnector(this); if (getIntent().getExtras() == null) { dbConnector.insertContact(nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), minEt.getCurrentMinute().toString(), codeEt.getText().toString()); } else { dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), minEt.getCurrentMinute().toString(),/* Storing as String*/ codeEt.getText().toString()); } }}\[/code\]
 
Back
Top