How to place 2 TextView at same place with if else condition in Android
In my app I am showing the latitude and longitude of a place. I have place a separate layout for those two. Now the problem is if there is no network I want to show an er开发者_C百科ror message at the same place, i.e. within the same layout.
If there is network I want to show the TextView1, the values of latitude and longitude else I want to show the TextView2. Is it possible can anyone explain me this with some sample codes.
Is there any other simple way to do this?
Is there any API to check network?
You can use the same TextView:
boolean condition;
TextView tv = (TextView) findViewById(R.id.your_text_view);
if (condition) {
tv.setText("something");
}
else
{
tv.setText("something else");
}
You can do it in java source files. I believe it would be
Textview v = findViewById(your view's id); if(no network) { v.setText("what ever you want"); }
else { v.setText("you longitude and lattitude text would go here"); }
精彩评论