Passing values to another activity via intent - android

I am trying to pass some values via intent and show them in a new activity. I have tried many solutions but the problem is always the same: There are two textviews in new activity and when I set the text via code but only the textview tv2 appears.
Please help. I am new to android and java and trying to learn the concepts for a new app.
MainActivity.java:
Intent intent = new Intent(MainActivity.this,Details.class);
intent.putExtra(NAME, name);//name is string type
intent.putExtra(VALUE, value);//value is long type
startActivity(intent);
Details.java :
TextView tv1 = (TextView) findViewById(R.id.name);
TextView tv2 = (TextView) findViewById(R.id.value);
Intent intent = getIntent();
String name = intent.getStringExtra(MainActivity.NAME);
Long value=intent.getLongExtra(MainActivity.VALUE, 0);
String value_text=value.toString();
tv1.setText(name);
tv2.setText(value_text);
Layout For Details.java(Image is for further experiments):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="40sp" />
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp" />
</LinearLayout>

Related

Android AutoCompleteTextView return wrong string

I have a little problem in my android app. I want to put a word in an AutoCompleteTextView and then jump to a specific Activity(depend on the word that the user gave).
The problem is that, when i give a specific word, the program does not correspond with the correct answer as expected but returns a wrong toast message. However with the log that i put i see the correct answer. I think that the solution is silly but i stuck and need to solve this.
the code:
Activity.java
public class paralActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paral);
final String [] temp = {"one","two","three"};
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
actv.clearListSelection();
final RelativeLayout myRelative = (RelativeLayout) findViewById(R.id.find);
myRelative.setVisibility(View.INVISIBLE);
ImageView myImage = (ImageView) findViewById(R.id.aktoploika);
myImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(paralActivity.this, topParalActivity.class);
startActivity(intent);
}
});
ImageView myOtherImage = (ImageView) findViewById(R.id.aeroporika);
myOtherImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
myRelative.setVisibility(View.VISIBLE);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(paralActivity.this, android.R.layout.select_dialog_item, temp);
//Getting the instance of AutoCompleteTextView
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);//will start working from first character
actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
actv.setTextColor(Color.RED);
ImageView findBeach = (ImageView) findViewById(R.id.find_beach);
findBeach.setOnClickListener(new View.OnClickListener() {
#Override
** public void onClick(View view) {
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
String choice = actv.getText().toString();
Log.i("Answer",choice);
if (choice == "one"){
Intent firstIntent = new Intent(paralActivity.this, nauagioActivity.class);
startActivity(firstIntent);
}else if (choice == temp[1]){
Intent secondIntent = new Intent(paralActivity.this, gerakasActivity.class);
startActivity(secondIntent);
}else if (choice == temp[2]){
Intent thirdIntent = new Intent(paralActivity.this, limnionasActivity.class);
startActivity(thirdIntent);
}else{
Toast.makeText(paralActivity.this,"wrong",Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
To help u understand, in this activity a have 2 imageViews. When the user presses the second, a relativeLayout appears (with an AutoCompleteTextView and a button inside). After the user writes the word when presses the button it must go to the specific activity. I declared a String Array (temp[3]) with three words inside and 3 activities for each of the words.
The problem starts in the last onclick method that i put ** . Every time i put a correct word from the Array i take the Toast message but in the log i see the correct.
here is Activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_paral"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main"
android:scaleX="2"
tools:context="com.example.billy.zakynthosapp.paralActivity">
<TextView
android:id="#+id/categories"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome"
android:text="#string/categories"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textSize="11sp"
android:textStyle="bold"
android:textColor="#color/welcome"
android:textAllCaps="true"/>
<ImageView
android:id="#+id/aktoploika"
android:layout_centerHorizontal="true"
android:layout_width="130dp"
android:layout_height="50dp"
android:layout_below="#id/categories"
android:layout_marginTop="35dp"
android:scaleType="centerCrop"
android:src="#drawable/par1" />
<TextView
android:id="#+id/aktoploika_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/aktoploika"
android:layout_alignTop="#+id/aktoploika"
android:layout_alignRight="#+id/aktoploika"
android:layout_alignBottom="#+id/aktoploika"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/paralies"
android:textSize="22sp"
android:textColor="#color/categories"
android:textStyle="bold"/>
<ImageView
android:id="#+id/aeroporika"
android:layout_centerHorizontal="true"
android:layout_width="130dp"
android:layout_height="50dp"
android:layout_below="#id/aktoploika"
android:layout_marginTop="35dp"
android:scaleType="centerCrop"
android:src="#drawable/par2" />
<TextView
android:id="#+id/aeroporika_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/aeroporika"
android:layout_alignTop="#+id/aeroporika"
android:layout_alignRight="#+id/aeroporika"
android:layout_alignBottom="#+id/aeroporika"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/search"
android:textSize="22sp"
android:textColor="#color/categories"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/aeroporika"
android:layout_marginTop="50dp"
android:layout_centerInParent="true"
android:background="#color/categories"
android:scaleX="0.5">
<TextView
android:id="#+id/textView_1"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:textSize="20sp"
android:layout_centerHorizontal="true"
android:text="#string/find_paral"
android:textColor="#android:color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/find_beach"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="200dp"
android:src="#drawable/find"
android:onClick="find"/>
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView_1"
android:layout_marginTop="10dp"
android:ems="10"
android:text="">
<requestFocus />
</AutoCompleteTextView>
</RelativeLayout>
Can anyone help me with this?
Thanks a lot!
Try choice.equals("one") instead of choice == "one"

How to show both the layout and the message?

I created a message activity and it works but my problem is the xml layout that I created is not showing, only the message or vice versa (the layout is showing without the message).How do I solve this?
here is the code of the class:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = intent.getStringExtra (MESSAGE_KEY);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText (message);
setContentView(textView);
setContentView(R.layout.activity_fire_alert);
}
and here is the xml file that i want to show
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.user.tictactoeniandy.FireAlertActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="View Sender Location"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="91dp"
android:id="#+id/loc_button1"/>
</RelativeLayout>
You can only have 1 content view. The second one you set overwrites the other. The correct way to do this is to have a TextView inside your layout, and to set the text on that view to the message
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation:"vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.user.tictactoeniandy.FireAlertActivity">
<TextView
android:id="#+id/loc_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="View Sender Location"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="View Sender Location"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="91dp"
android:id="#+id/loc_button1"/>
</LinearLayout>
and in your activity code,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fire_alert);
Intent intent = getIntent();
String message = intent.getStringExtra (MESSAGE_KEY);
TextView textView = (TextView)findviewbyid(R.id.loc_textview);
textView.setTextSize(40);
textView.setText (message);
}
you can have only one set content view. try to update your layout and code with mine and check it will show both.
The setContentView() method, as the name suggests, sets the content of your activity. To solve this, place your TextView directly on your layout file, for example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
...>
<Button
android:layout_width="wrap_content"
android:layout_height="
...
.../>
<TextView
android:id="#+id/text_view_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
On your Java code, make a TextView using the id you just created on your layout, then set the message text on it.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fire_alert);
TextView textView = (TextView) findViewById(R.text_view_message);
Intent intent = getIntent();
String message = intent.getStringExtra (MESSAGE_KEY);
textView.setText (message);
}

A lot activity in one layout

I am developing Restaurant menu app. I have 9 image button in activity_main.xml. For example: If when i clicked soup image button, the app will soup price and soup image in other layout. But i dont want create 9 layouts file for this. All of prices appear one layout. I didnt write method for this. I am waiting your help. Sorry for my bad english.
This is my menu.
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton2"
android:layout_gravity="left|top"
android:background="#drawable/corbalar"
android:contentDescription="#string/corbalar"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton3"
android:layout_gravity="center_horizontal|top"
android:background="#drawable/zeytinyaglilar"
android:contentDescription="#string/zeytinyaglilar"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton4"
android:layout_gravity="right|top"
android:background="#drawable/spesiyaller"
android:contentDescription="#string/spesiyaller"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton5"
android:layout_gravity="left|center_vertical"
android:background="#drawable/pideler"
android:contentDescription="#string/pideler"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton6"
android:layout_gravity="center"
android:background="#drawable/salatalar"
android:contentDescription="#string/salatalar"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton7"
android:layout_gravity="right|center_vertical"
android:background="#drawable/kebaplar"
android:contentDescription="#string/kebaplar"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton8"
android:layout_gravity="left|bottom"
android:background="#drawable/tatlilar"
android:contentDescription="#string/tatlilar"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton9"
android:layout_gravity="center_horizontal|bottom"
android:background="#drawable/mesrubatlar"
android:contentDescription="#string/mesrubatlar"
android:clickable="true"
android:onClick="degistirActivity"/>
<ImageButton
android:layout_width="130dp"
android:layout_height="170dp"
android:id="#+id/imageButton10"
android:layout_gravity="right|bottom"
android:background="#drawable/sicakicecekler"
android:contentDescription="#string/sicakicecekler"
android:clickable="true"
android:onClick="degistirActivity"/>
This is the place I'll show information.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="tr.edu.fatih.nad0.com.kilislimenu.fiyatGoster">
//my items image
<ImageButton
android:layout_width="250dp"
android:layout_height="250dp"
android:id="#+id/imageButton11"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/gosterilecekyemek" />
//my items price
<TextView
android:layout_width="200dp"
android:layout_height="50dp"
android:id="#+id/textView"
android:layout_below="#+id/imageButton11"
android:layout_centerHorizontal="true" />
What you'll want to do is use an intent with extras to pass information of the clicked item to the activity. There's a couple of ways to do this:
1) Manually create an OnClickListener for each item (ideally, you'd generate your items from a SQLite database rather than having a static list).
Using an OnClickListener would look something like this:
ImageButton myButton = (ImageButton) findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent priceIntent = new Intent(getApplicationContext(), priceActivity.class);
priceIntent.putExtra("price",6.99);
priceIntent.putExtra("name","Hamburger");
startActivity(priceIntent);
}
});
Then in your onCreate method for priceActivity.class, you'd read the values like this:
Bundle extras = getIntent().getExtras();
double price = extras.getDouble("price");
String name = extras.getString("name");
2) Use the onClick attribute in your XML to process the information through an identifying tag or some such.
In your XML you can specify android:onClick="myMethod" as well as an identifying tag, like android:tag="hamburger". Then you'd make your myMethod:
public void myMethod(View v) {
String tagId = v.getTag().toString();
// Create intent with extras like above
}
Again, ideally you'd be loading all of this information from a database so that you can easily access the information with fewer methods rather than manually entering the hard-coded data straight into the app.
you can follow below link to workout with your problem.
http://developer.android.com/training/basics/firstapp/starting-activity.html
Alternatively,
you can implement method like this on your button.
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
}
On another Activity, you can receive Intent and Display your price.
Intent intent = getIntent();
String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);

how to setText() in android embedded card

Here I have a nice simple table layout to display the contents of my database.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tableLayout1">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/Date"
android:layout_weight="0.3333"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Systolic"
android:id="#+id/Systolic"
android:layout_weight="0.3333"
android:textAlignment="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Diastolic"
android:id="#+id/Diastolic"
android:layout_weight="0.3333" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DateInfo"
android:layout_weight="0.3333"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SystolicInfo"
android:layout_weight="0.3333"
android:textAlignment="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DiastolicInfo"
android:layout_weight="0.3333" />
</TableRow>
</TableLayout>
Here is the method that is called in the onCreate of the calling activity:
private View buildView() {
//CardBuilder card = new CardBuilder(this, CardBuilder.Layout.MENU);
//card.setText("It worked!!!");
CardBuilder previousReadings = new CardBuilder(this, CardBuilder.Layout.EMBED_INSIDE);
previousReadings.setEmbeddedLayout(R.layout.blood_pressures);
TextView tv = (TextView) findViewById(R.id.SystolicInfo);
//tv.setText("Why won't this work?");
MyDatabase info = new MyDatabase(this);
info.open();
String data = info.getData();
info.close();
System.out.println(data);
//tv.setText(data);
return previousReadings.getView();
//return card.getView();
}
}
I used the CarBuilder object card that was a simple card without an embedded layout and this worked fine. I then commented it out and tried implementing the embedded card which also works fine (above). However the problem arises when I try to tv.setText(). Whether this is just a constant or the "data" variable. The logcat reads "unable to load Activity:... null pointer exception.
Can anybody shed some light on the problem? I have tried EditTexts as well as TextViews and neither work. Thanks in advance.
Use previousReadings.getView() call findViewById to access TextView from Card:
....
System.out.println(data);
View view= previousReadings.getView();
TextView tv = (TextView)view.findViewById(R.id.SystolicInfo);
tv.setText("Why won't this work?");
return view;

Start activity using intent with extra does not show all the extras

Inside a setOnItemClickListener I use an intent to start a new activity. I put 7 strings as extras for this intent. When I click an item (of a ListView) I want all these extras to be displayed (on a new screen). But I see only the first 4 extras. Here's the layout file for the new activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/address_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/city_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/zip_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/state_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
<TextView
android:id="#+id/name_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/number_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/store_id_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip"/>
</LinearLayout>
Then here's the listener code:
lv_custom.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Log.v("ITEM",lv_custom.getItemAtPosition(position).toString());
c.moveToPosition(position);
String adr = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_ADDRESS));
String city = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_CITY));
String name = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_NAME));
String store_id = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_STORE_ID));
String phone = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_PHONE));
String zip = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_ZIP));
String state = c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_STATE));
Intent intent=new Intent(DisplayActivity.this,DisplayInfoActivity.class);
intent.putExtra("Address: ",adr);
intent.putExtra("City: ", city);
intent.putExtra("Zip: ", " " + zip + ", ");
intent.putExtra("State: ", state);
intent.putExtra("Name: ", name);
intent.putExtra("Store ID: ", "Store ID " + store_id);
intent.putExtra("Phone: ", phone);
startActivity(intent);
}
});
Here's the new activity code:
public class DisplayInfoActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_entry);
TextView address = (TextView) findViewById(R.id.address_entry);
TextView city = (TextView) findViewById(R.id.city_entry);
TextView zip = (TextView) findViewById(R.id.zip_entry);
TextView state = (TextView) findViewById(R.id.state_entry);
TextView name = (TextView) findViewById(R.id.name_entry);
TextView store_id = (TextView) findViewById(R.id.store_id_entry);
TextView phone = (TextView) findViewById(R.id.number_entry);
Intent intent = getIntent();
address.setText(intent.getStringExtra("Address: "));
city.setText(intent.getStringExtra("City: "));
zip.setText(intent.getStringExtra("Zip: "));
state.setText(intent.getStringExtra("State: "));
name.setText(intent.getStringExtra("Name: "));
store_id.setText(intent.getStringExtra("Store ID: "));
phone.setText(intent.getStringExtra("Phone: "));
}
}
The problem is that it shows only the address, the city, the zip code, and the state. It does not show the name, store id and the phone number. What happens with them? Why they are not shown/seen on the new screen? Actually, before I added more extras, I could see all the extras in my intent. Is there a problem with the number of extras? Thanks for help, if you have an answer for me!
You can simplify adding extras - no need to use extra characters as key:
intent.putExtra("Address",adr);
intent.putExtra("City", city);
intent.putExtra("Zip", " " + zip + ", ");
intent.putExtra("State", state);
intent.putExtra("Name", name);
intent.putExtra("StoreID", "Store ID " + store_id);
intent.putExtra("Phone", phone);
and correspondingly, in your DisplayInfoActivity:
address.setText(intent.getStringExtra("Address"));
city.setText(intent.getStringExtra("City"));
zip.setText(intent.getStringExtra("Zip"));
state.setText(intent.getStringExtra("State"));
name.setText(intent.getStringExtra("Name"));
store_id.setText(intent.getStringExtra("StoreID"));
phone.setText(intent.getStringExtra("Phone"));
Next, have you tried printing the extras to logcat, in case your layout is incorrect? Add this below the lines where you retrieve extras:
Log.d("MYTAG", "Name: " + intent.getStringExtra("Name"));
and see if you can see it in logcat. If yes, maybe your layout is not showing all those TextViews.
Btw, try moving the last 3 TextViews (name, store_id and number) in your layout file INSIDE the second LinearLayout (together with all the other textviews), just to see if they are displayed.
Your inner horizontal LinearLayout's height is set to match_parent:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
Thus, it stretches to the bottom of the screen and leaves no place for your other three TextViews. Therefore it should be set to wrap_content:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
Your layout is wrong
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/address_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
...
You should have
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/address_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
...
Because your second LinearLayout is taking all the remaining screen

Categories

Resources