I have a problem when I reach the last nested activity with the tab
activity. so when I press on one of the tab(Branch Search) it takes me
to a page when I have a edittext and go button when I press the go
button to get the locations of the specific zipcode I get the
locations with the tab bar, but when I press the location tab bar
again it shows me the location results intsted of the edittext with
the go button
any suggestion to fix this problem
below is my code
I have MainActivity class which extends the TabActivity and define all
the tabs
public class MainActivity extends TabActivity
{
public TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, DashBoard.class);
spec =
tabHost.newTabSpec("dashboard").setIndicator("DashBoard").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, VehicleSearch.class);
spec =
tabHost.newTabSpec("vehicleSearch").setIndicator("VehicleSearch").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, BranchSearch.class);
spec =
tabHost.newTabSpec("branchSearch").setIndicator("BranchSearch").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(3);
}
I also have the BranchSearchHelper class which extends ActivityGroup
public class BranchSearchHelper extends ActivityGroup
{
public static BranchSearchHelper branchSearch;
private ArrayList<View> history;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
branchSearch = this;
this.history = new ArrayList<View>();
View view =
getLocalActivityManager().startActivity("BranchSearch", new
Intent(this,BranchSearch.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
replaceView(view);
}
public void replaceView(View v)
{
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new
View.
setContentView(v);
}
public void back()
{
if(history.size() > 0) {
history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
}
else
{
finish();
}
}
@Override
public void onBackPressed()
{
BranchSearchHelper.branchSearch.back();
return;
}
}
The class BranchSearch extends Activity
public class BranchSearch extends Activity implements OnClickListener
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.branchsearch);
Button locSearch = (Button)
findViewById(R.id.btnlocSearch);
locSearch.setOnClickListener(this);
}
public void onClick(View v)
{
// TODO Auto-generated method stub
EditText editText = (EditText)
findViewById(R.id.lsearch);
Bundle bundle = new Bundle();
bundle.putString("zipCode",
editText.getText().toString() );
Intent i = new Intent(getApplicationContext(),
LocationSearchResults.class);
i.putExtras(bundle);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View view =
BranchSearchHelper.branchSearch.getLocalActivityManager().startActivity("Locations
Results",i).getDecorView();
BranchSearchHelper.branchSearch.replaceView(view);
}
}
the class LocationSearchResults is where I have the problem
package IAA.IAAProject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import IAA.IAAProject.R;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
public class LocationSearchResults extends Activity
{
private TextView txtData;
//private EditText editText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationsearchresults);
txtData = (TextView) findViewById(R.id.txtData);
Bundle bundle = this.getIntent().getExtras();
String zipCode = bundle.getString("zipCode").trim();
String url = "https:// ";
url += zipCode;
connect(url);
}
private String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the
BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which
means
* there's no more data to read. Each line will appended to a
StringBuilder
* and returned as String.
*/
BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}
/* This is a test function which will connects to a given
* rest service and prints it's response to Android Log with
* labels "Praeda".
*/
public void connect(String url)
{
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet(url);
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
// Examine the response status
Log.i("RestAndroid11",response.getStatusLine().toString());
// Get hold of the response entity
HttpEntity entity = response.getEntity();
// If the response does not enclose an entity, there is
no need
// to worry about connection release
if (entity != null) {
// A Simple JSON Response Read
InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
Log.i("RestIAA11",result);
JSONArray entries = new JSONArray(result);
String output = "";
for(int i=0;i<entries.length();i++)
{
JSONObject jobj = entries.getJSONObject(i);
output+="------------\n";
output += "branchCity : " +
jobj.getString("branchCity") + "\n
output += "branchDistanceRank : " +
jobj.getString("branchDistanceRank") + "\n";
output += "branchFax : " +
jobj.getString("branchFax") + "\n";
output += "branchName : " +
jobj.getString("branchName") + "\n";
output += "branchPhone: " +
jobj.getString("branchPhone") + "\n";
output += "branchState : " +
jobj.getString("branchState") + "\n
\n";
}
txtData.setText(output);
// Closing the input stream will trigger
connection release
instream.close();
}
else
Toast.makeText(getBaseContext(), " the entity
is equals to null",
Toast.LENGTH_LONG).show();
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
txtData.setText("Error w/file: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I beleive I should add some code after txtData.setText(output);
Thank you in advance for your help
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en